Can't find package.json in directory in CircleCI build - continuous-integration

I have a repo that contains two subprojects. Just for completeness a frontend project and a firebase cloud-function project (both using separate package.jsons). Now for this project, I want to start two jobs concurrently. But I can't get the setup done with CircleCI. I don't have any cache-configuration.
project structure
-creepy-stories
-.circleci
-cloud-functions
-functions
package.json
-frontend
package.json
config.yml
version: 2.1
jobs:
cloud-functions:
docker:
- image: circleci/node:10.8.0
working_directory: ~/creepy-stories/cloud-functions/functions
steps:
- checkout
- run: npm install
- run: npm run lint
- run: npm run build
frontend:
docker:
- image: circleci/node:10.8.0
working_directory: ~/creepy-stories/frontend
steps:
- checkout
- run: npm install
- run: npm run lint
- run: npm run build
- run: npm run test:coverage
workflows:
version: 2
cloud-functions_and_frontend:
jobs:
- cloud-functions
- frontend
So now my I guess my problem is the environment cant find my package.json file. The error that is printed looks as follows:
npm run lint
#!/bin/bash -eo pipefail
npm run lint
npm ERR! path /home/circleci/creepy-stories/frontend/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/circleci/creepy-stories/frontend/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /home/circleci/.npm/_logs/2019-04-20T13_08_45_252Z-debug.log
Exited with code 254
I don't know if it is right to set the working directory twice in my configuration, but it is at least set in two diff. jobs.
Update
I managed to get it work if I checkout the root of the Project and then cd to the needed folder and execute the scripts. But this isn't really DRY (don't repeat yourself) maybe some of you have a better solution:
version: 2.1
jobs:
cloud-functions:
docker:
- image: circleci/node:10.8.0
working_directory: ~/creepy-stories
steps:
- checkout
- run: cd cloud-functions/functions && npm install
- run: cd cloud-functions/functions && npm run lint
- run: cd cloud-functions/functions && npm run build
web:
docker:
- image: circleci/node:10.8.0
working_directory: ~/creepy-stories
steps:
- checkout
- run: cd web && npm install
- run: cd web && npm run lint
- run: cd web && npm run build
- run: cd web && npm run test:coverage
workflows:
version: 2
concurrently:
jobs:
- cloud-functions
- web

When you checkout, you automatically copy the root of the git repository into the current working directory. If you want your working directory to be a sub-directory of the root, you need to give the checkout step a path that copies the files into a parent of the working directory.
Example:
working_directory: ~/creepy-stories/cloud-functions
steps:
- checkout:
path: ~/creepy-stories
Link to the documentation: https://circleci.com/docs/2.0/configuration-reference/#checkout

I think you've got an added directory in the way.
You should add an extra run to your CircleCi frontend task that does a pwd and then a ls -la.
You'll probably find that the checkout has ended up inside a directory with the same name as your repo.
Edit to answer followup question:
If i remember correctly, the checkout command, always put it in the root of the server, so you can update the working directory to accommodate that. Like so
working_directory: ~/creepy-stories/web
steps:
- checkout
- run: npm install
- run: npm run lint
- run: npm run build
- run: npm run test:coverage

Related

npm install #solana/web3.js from github

const web3 = require("#solana/web3.js");
I'm trying to run #solana/web3.js from a fork so I need to install it using
npm i https://github.com/redazul/solana-web3.js.git
the fork is being done to add console.logs for educational purposes
I also tried to build the solana-web3.js source repo
but npm run build does not work
$ npm run build
> #solana/web3.js#0.0.0-development build
> npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen
npm ERR! Missing script: "clean;"
npm ERR!
npm ERR! Did you mean this?
npm ERR! npm run clean # run the "clean" package script
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
The problem was related to target / build environment
The following worked using WSL + Ubuntu 20.04
npm i
npm run build
Then commit to github

Azure DevOps NPM task returns 403 while bash task succeeds

I'm trying to switch from using Azure DevOps Bash task to NPM task and when running the NPM task it fails with 403 while with Bash task it works.
This is the bash task that is working:
- task: Bash#3
displayName: 'npm ci'
target:
commands: any
inputs:
targetType: 'inline'
script: 'npm ci'
workingDirectory: './apps/${{ parameters.appName }}'
and this is the npm task that I'm getting an error for:
- task: Npm#1
displayName: 'npm ci'
target:
commands: any
inputs:
command: 'ci'
workingDir: './apps/${{ parameters.appName }}'
This is the complete error I'm getting:
npm ERR! code E403
npm ERR! 403 403 Forbidden - GET https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/AzDevOps_azpcontainer/.npm/_logs/2022-11-20T14_20_22_151Z-debug-0.log
##[warning]Couldn't find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1
Finishing: npm ci
In general I wanted to know what's the difference between these two tasks? Aren't they supposed to be identical? And what could be causing the different result?
You should create a Azure DevOps Service connection for npm repositories and specifically with the credentials you use for npmjs.
The NPM task for Azure DevOps can use the Service Connection as specified in the docs for the NPM task

Laravel vapor github action throws permission error

I'm trying to use Github Actions to deploy to vapor. I'm using the action as decribed on https://docs.vapor.build/1.0/projects/deployments.html#deploying-from-ci.
name: Deploy
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout#v2
- name: Setup PHP
uses: shivammathur/setup-php#v2
with:
php-version: 8.0
tools: composer:v2
coverage: none
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Require Vapor CLI
run: composer global require laravel/vapor-cli
- name: Deploy Environment
run: vapor deploy
env:
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}
The github action keeps failing due to this error:
Error Output:
================
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#github.com/jawid-h/protobuf
.js.git
npm ERR!
npm ERR! Warning: Permanently added the RSA host key for IP address '140.82
.113.4' to the list of known hosts.
npm ERR! git#github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
I have already tried passing the GITHUB_TOKEN, but that somehow doesn't work.
This is a ssh key error. You are not using the same ssh key as the one you imported in Github or it is not accessible in some way. You need to check ~/.ssh/id_?sa or manually specify another file.
Or you could also switch to anonymous https protocol by changing the repository URL if you don't need write access by replacing:
ssh://git#github.com/jawid-h/protobuf.js.git
with
https://github.com/jawid-h/protobuf.js.git
In my case I'm use GITLAB platform and I get the same error. I solve the issue with delete 'package-lock.json' and run a new one 'npm install'.
On package-lock.json, you find this line "lockfileVersion".
The version before solve issue:
"lockfileVersion": 2,
The version after solve issue:
"lockfileVersion": 1,

Coveralls coverage suddenly started work with errors on GitLab and Appveyor with the same call

Usually I used the similar .gitlab-ci.yml code to send reports to coveralls for some of my repos:
install_dependencies:
stage: build
script:
- npm install -g gulp nyc
- npm install coveralls
- npm install
artifacts:
paths:
- node_modules/
testing:
stage: test
script:
- npx nyc gulp test
- npx nyc report --reporter=html
- npx nyc report --reporter=text-lcov | npx ./node_modules/coveralls/bin/coveralls.js
artifacts:
paths:
- public
- coverage
- .nyc_output
And on Appveyor:
install:
- ps: Install-Product node $env:nodejs_version
- npm install -g gulp nyc coveralls
- npm install
test_script:
- node --version
- npm --version
- gulp --version
- cmd: npx nyc gulp test
after_test:
cmd: npx nyc report --reporter=text-lcov | npx coverall
It worked well few months ago, but today I found that it doesn't work anymore for all my repos, I got the error:
npm ERR! code ENOTDIR
npm ERR! syscall open
npm ERR! path /builds/username/proj/node_modules/coveralls/bin/coveralls.js/package.json
npm ERR! errno -20
npm ERR! ENOTDIR: not a directory, open '/builds/username/proj/node_modules/coveralls/bin/coveralls.js/package.json'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-11-06T03_01_59_736Z-debug.log
node:events:304
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:162:15)
at writeGeneric (node:internal/stream_base_commons:153:3)
at Socket._writeGeneric (node:net:763:11)
at Socket._write (node:net:775:8)
at writeOrBuffer (node:internal/streams/writable:388:12)
at Socket.Writable.write (node:internal/streams/writable:333:10)
at ConsoleWriter.write (/root/.npm/_npx/6e14a84d153b8cb9/node_modules/istanbul-lib-report/lib/file-writer.js:80:28)
at ConsoleWriter.println (/root/.npm/_npx/6e14a84d153b8cb9/node_modules/istanbul-lib-report/lib/file-writer.js:35:14)
at TextLcov.onDetail (/root/.npm/_npx/6e14a84d153b8cb9/node_modules/istanbul-reports/lib/lcovonly/index.js:31:16)
at Visitor.value (/root/.npm/_npx/6e14a84d153b8cb9/node_modules/istanbul-lib-report/lib/tree.js:38:38)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:188:8)
at emitErrorCloseNT (node:internal/streams/destroy:153:3)
at processTicksAndRejections (node:internal/process/task_queues:80:21) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}
npm ERR! code 1
npm ERR! path /builds/username/proj
npm ERR! command failed
npm ERR! command sh -c nyc report '--reporter=text-lcov'
When I've installed coveralls module globally and changed the command to … | npx coveralls:
npm WARN exec The following package was not found and will be installed: coveralls
npm WARN deprecated har-validator#5.1.5: this library is no longer supported
npm WARN deprecated request#2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
/root/.npm/_npx/4d97078606416726/node_modules/coveralls/bin/coveralls.js:19
throw err;
^
Bad response: 500 {"message":"Build processing error.","error":true,"url":""}
(Use `node --trace-uncaught ...` to show where the exception was thrown)
npm ERR! code 1
npm ERR! path /builds/username/proj
npm ERR! command failed
npm ERR! command sh -c coveralls
The same, but shorter, on Appveyor for now:
C:\Users\appveyor\AppData\Roaming\npm\node_modules\coveralls\bin\coveralls.js:19
throw err;
^
Bad response: 500 {"message":"Build processing error.","error":true,"url":""}
Command exited with code 1
I can't understand, is it temporary problem of Coveralls, or Istanbul/NYC, or some changes took the place permanently, and the code should be changed accordingly in some way.

Running Vapor from Homestead failds

I installed Vapor in a brand new Laravel up. When I try to run 'vapor deploy production' I get this error:
Running Command: npm ci && npm run prod && rm -rf node_modules
npm ERR! cipm can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm#5 or later to generate it, then try again.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2019-10-23T21_24_09_128Z-debug.log
In Process.php line 254:
The command "npm ci && npm run prod && rm -rf node_modules" failed.
Exit Code: 1(General error)
Working directory: /home/vagrant/code/sales2/.vapor/build/app
Output:
================
Error Output:
================
npm ERR! cipm can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVers
ion >= 1. Run an install with npm#5 or later to generate it, then try again.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2019-10-23T21_24_09_128Z-debug.log
I sucessfully installed vapor. Created a new project and left the domain setting at default.
You didn't specify what your host operating system was, but I assume it's windows, when you ran "vagrant up" did you do so as administrator?
That said, this is an issue with npm and not Vapor. I'd running the "npm ci && npm run prod && rm -rf node_modules" command ssh'd into your vagrant console and troubleshoot from there.
You may not have configured the node package manager for this project. From your computer and not the homestead if you are using, run this command
<project directory>: npm install
This will create the necessary file.

Resources