Github actions looking for package.json in a nested folder - jestjs

Github action searches for package.json in the project, but in a folder with the same name as the project ('/home/runner/work/javascript-coding-challenges/javascript-coding-challenges/package.json'). I don't have package.json there.
My jest.yaml
name: Run Jest tests
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Install modules
run: npm install
- name: Run tests
uses: stefanoeb/jest-action#1.0.3
with:
jestArgs: passWithNoTests
Error:
npm WARN saveError ENOENT: no such file or directory, open '/home/runner/work/javascript-coding-challenges/javascript-coding-challenges/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/runner/work/javascript-coding-challenges/javascript-coding-challenges/package.json'
npm WARN javascript-coding-challenges No description
npm WARN javascript-coding-challenges No repository field.
npm WARN javascript-coding-challenges No README data
npm WARN javascript-coding-challenges No license field.
I am not entirely sure how to remedy this. Is it possible to "exit" from the current folder? (like cd ..) This will allow github action to find the correct folder where package.json is located.
I've checked these two answers:
github actions can not find package.json
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'
but both of them are not answering my question (I see in first one changing uses into ./ but I want to use this specific action)

Related

how to get the dependencies of a project with a package-lock.json but no package.json?

I have a project with a package-lock.json but no package.json.
When I run npm install I get the following:
npm WARN saveError ENOENT: no such file or directory, open '/home/neubert/myproject/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/neubert/myproject/package.json'
npm WARN myproject No description
npm WARN myproject No repository field.
npm WARN myproject No README data
npm WARN myproject No license field.
up to date in 0.279s
found 0 vulnerabilities
Any ideas how I can make it so that the deps in the package-lock.json are downloaded, even if package.json isn't present?
Well my first thought would be to run
npm rebuild
If you have installed previously it will rebuild all the packages and they will print out on your screen. Then its just a matter of adding them back to a package.js
here is a link to npmjs.com and their cli commands... its handy. i have it bookmarked in my cheat sheets

Getting error: "saveError ENOENT: no such file or directory, open '.../package.json'

I am attempting to install newsapi via the command: npm install newsapi --save.
That installs two dependent packages (core-js and node-fetch) as well as newsapi itself. I run the command in my project folder. I have no issues with core-js and node-fetch, but I get the following warnings regarding newsapi.
npm WARN saveError ENOENT: no such file or directory, open 'Users/user_name/project/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'Users/user_name/project/package.json'
npm WARN project No description
npm WARN project No repository field.
npm WARN project No README data
npm WARN project No license field.
After the installation, package-lock.json is created in my project folder and Users/user_name/project/node-modules/newsapi/package.json does exist. I don't know why the installation asks me to open Users/user_name/project/package.json. Why would it be in my project folder and not in the module's folder?
I tried solutions I read in other threads including deleting package-lock.json and retrying the installation and using npm init. Neither of those methods worked.
I also tried copying and pasting package.json to the project folder (because the warnings prompt me to open Users/user_name/project/package.json) but that did not solve my problems either.
How can I successfully install the module?

npm install in GitHub Action fails with "ENOENT: no such file or directory" - Works fine elsewhere

I am currently working on replacing our Drone CI installation with GitHub Actions.
The Action Workflow I have so far boils down to the following .github/workflows/ci.yml file:
on: [ push, pull_request ]
name: CI
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Install Node
uses: actions/setup-node#v1
with:
node-version: '13.x'
- name: Install Dependencies
run: npm install
The log itself comes out as a long series of npm WARN tar ENOENT: no such file or directory ala the truncated list below.
2020-04-29T21:15:31.7899082Z npm install
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/acorn-26d8ba97/dist/acorn.js.map'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/coffeescript-acee515b/lib/coffee-script/register.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/coffeescript-acee515b/lib/coffee-script/repl.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/coffeescript-acee515b/lib/coffee-script/rewriter.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/tslint-c216b578/LICENSE'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/eslint-cd3dbe58/LICENSE'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/eslint-cd3dbe58/README.md'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/typescript-b4b55d18/lib/diagnosticMessages.generated.json'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/jquery-1794793b/dist/jquery.min.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-05c1df31/fp/_convertBrowser.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-70e4a396/fp/_convertBrowser.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-79f5ae17/fp/_convertBrowser.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-e49b02f6/fp/_convertBrowser.js'
npm WARN tar ENOENT: no such file or directory, open '/home/runner/work/project/project/node_modules/.staging/lodash-16fa050d/fp/_convertBrowser.js'
The advice I have found online is to rm package-lock.json but that's not an acceptable solution as I need to test our code with the exact versions of our dependencies we have locked.
Further, I don't believe there is anything wrong with our package-lock.json file to begin with because it still npm install 's as expected both locally and on our Drone CI installation.
At long wait, I found the solution here:
Install an npm module from a private GitHub repository using GitHub Actions
- uses: actions/checkout#v2
with:
persist-credentials: false
- uses: actions/setup-node#v1
with:
node-version: 12.x
- run: git config --global url."https://${{ secrets.PAT }}#github.com/".insteadOf ssh://git#github.com/
- run: npm ci
...
I had tried basically all of this on my own but the most important part was missing:
with:
persist-credentials: false
actions/checkout#v2 will by default mess with some settings for Git and prevent insteadOf from working properly.
This error condition can also happen if you are using a private npm package, and simply forget to add the secret to the repo.
E.g. if you have something like this in your GitHub Actions workflow:
- name: Add token for private package access to .npmrc
run: echo "//npm.pkg.github.com/:_authToken=$ACME_CORP_TOKEN" > ~/.npmrc
env:
ACME_CORP_TOKEN: ${{ secrets.ACME_CORP_TOKEN }}
...an action like the above won't fail if $ACME_CORP_TOKEN doesn't exist (though it would be better to make it do so), so if you've forgotten to actually add the ACME_CORP_TOKEN secret to the repository (in the Secrets tab of the repository settings), then you will get this same problem.
The enormous list of npm WARN tar ENOENT errors for normal-looking dependencies inside of node_modules won't make it obvious that the problem is actually the missing private registry access token.
We had this problem. Buried amongst an unending stream of tar ENOENT errors we spotted this other one (edited for brevity):
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#github.com/fivetran/doctrine.git
npm ERR! git#github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! exited with error code: 128
In our case the repository in question is public but for whatever reason npm is nevertheless trying to fetch it by ssh instead of https (unlike all our other dependencies).
We solved the problem simply by adding an extra step to our workflow to configure npm to use https instead:
steps:
- uses: actions/checkout#v2
with:
persist-credentials: false
- name: Reconfigure git to use HTTP authentication
run: >
git config --global url."https://github.com/".insteadOf
ssh://git#github.com/
# etc.

nodejs project build through jenkins

Hi Iam new to nodejs projects.
I am building a cicd pipeline for jenkins. I configured git and in build section iam using npm install for build in jenkins.
The build shows success bot no node_modules or target getting generated. Below message shows package.jsonis missing but that is my jenkins workspace.
This is my error:
npm install
npm WARN saveError ENOENT: no such file or directory, open '/var/lib/jenkins/workspace/test2/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/var/lib/jenkins/workspace/test2/package.json'
npm WARN test2 No description
npm WARN test2 No repository field.
npm WARN test2 No README data
npm WARN test2 No license field.
up to date in 0.061s
Finished: SUCCESS
Please check if package.json file is present in folder /var/lib/jenkins/workspace/test2/

No such file package.json when running npm i

When I run the following commands:
npm i && npm run
I get the following error:
npm WARN saveError ENOENT: no such file or directory, open '/Users/Singh/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/Singh/package.json'
npm WARN Singh No description
npm WARN Singh No repository field.
npm WARN Singh No README data
npm WARN Singh No license field.
Why am I getting this error and how do I fix it?
First check there is package.json file or not if not create package.json file using npm init
The problem is that you're in the wrong directory -- you're in your user directory. If you cloned something from a repository, make sure you navigate to that directory before running npm i:
cd path/to/cloned/project
npm i && npm run <script_here>

Resources