Npm install falied in github action - node.js

I tried to create a github action that build my electron app with vue and vue-cli-plugin-electron-builder,but I can't install Dependencies by npm
my folder tree like this:
| .gitignore
| babel.config.js
| LICENSE
| package-lock.json
| package.json
| README.md
| vue.config.js
| yarn.lock
|
+---public
| favicon.ico
| index.html
| test.jpg
|
\---src
| App.vue
| background.js
| main.js
| preload.js
|
+---assets
| ...
|
\---components
...
when I run the CI,I found a error that
npm ci
shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
npm ERR! The `npm ci` command can only install with an existing package-lock.json or
npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm#5 or
npm ERR! later to generate a package-lock.json file, then try again.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\npm\cache\_logs\2021-08-01T04_59_20_385Z-debug.log
Error: Process completed with exit code 1.
this is my blank.yml:
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
name: Build
runs-on: windows-latest
steps:
- name: Install Node.js, NPM and Yarn
uses: actions/setup-node#v1
with:
node-version: 16
- name: Install Dependencies
run: |
npm ci
- name: Electron Build
run: |
npm run electron:build --windows nsis --x64 --ia32
I tried search on bing with the key word "npm install failed in github action" but I found nothing helpful.
also,I tried using 'npm install' instead the 'npm ci', but it showed the same error message that it can't find the package.json
the 'npm install' 's error message like this:
Run npm install
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path D:\a\example\example/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'D:\a\example\example\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! C:\npm\cache\_logs\2021-08-01T05_12_56_060Z-debug.log
Error: Process completed with exit code 1.
How can I solve it?
English is not my native language; please excuse typing errors.

You are not checking out your code and directly running NPM CI.
Below piece of code should do the job for you
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
name: Build
runs-on: windows-latest
steps:
- name: Checkout Code
uses: actions/checkout#v2
- name: Install Node.js, NPM and Yarn
uses: actions/setup-node#v1
with:
node-version: 16
- name: Install Dependencies
run: |
npm ci
- name: Electron Build
run: |
npm run electron:build --windows nsis --x64 --ia32

Related

Github actions with `github` protocol in `npm ci`

Here's my node.js.yml:
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test
In my package.json I have a dependency on uWebSockets.js as following:
"dependencies": {
// (...)
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.10.0",
// (...)
}
Now when the github action runs, on npm ci step I get the following output:
Run npm ci
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#github.com/uNetworking/uWebSockets.js.git
npm ERR!
npm ERR! Warning: Permanently added the ECDSA host key for IP address '140.82.112.3' 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
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-08-12T11_55_19_355Z-debug.log
Error: Process completed with exit code 1.
I have no clue what to change to make it work. Removing github: protocol explicit definition in package.json makes the library not install correctly in non-CI environment.
Thanks

Jest, command not found on GitLab

I'd like to execute my unit tests using JEST on GITLAB, but it seeem's not working.
It works on my local machine but not on GitLab.
The entire code of .gitlab-ci.yml :
image: node:16
cache:
paths:
- node_modules
install:
stage: build
script: npm ci
jest:
stage: test
script: npm run test:ci
artifacts:
when: always
reports:
junit:
- junit.xml
Package.json
"test": "jest",
"test:ci": "jest --config ./jest.config.js --ci --reporters=default --reporters=jest-junit"
Error :
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR! https://www.npmjs.com/forgot
npm ERR!
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR! npm login
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-05-12T08_05_01_634Z-debug-0.log
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
I found the issue by replacing the Node version (same version in my local machine) : image: node:14.
You need to have a step to install, better to check with GitLab CI document
image: node:16
cache:
paths:
- node_modules
install:
stage: build
script: npm ci
jest:
stage: test
script: npm run test:ci
artifacts:
when: always
reports:
junit:
- junit.xml

Can not install node module in GitHub action - npm ERR! error: remote origin already exists

I tried to create a GitHub action to build my application and it fails to install node module and return error that origin already exist
Please note that is is not a git fatal error that we get when push/pull
Please find my GitHub action code
name: My Desktop Build
on:
push:
branches:
- desktop-build
jobs:
release:
runs-on: macos-10.15
steps:
- name: Check out Git repository
uses: actions/checkout#v2
with:
path: current-repo
- name: Check out 2nd repo
uses: actions/checkout#v2
with:
repository: 5sfayas/private-repo
path: private-repo
ref: 'desktop-build'
ssh-key: ${{secrets.SSH_PRIVATE_KEY}}
- name: Adding SSH KEY
uses: webfactory/ssh-agent#v0.5.4
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Install npm in private-repo - 2nd repo
run: |
cd private-repo
npm i && npm run build
Error
npm ERR! code 3
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects remote add origin ssh://git#github.com/5sfayas/node-deperend-private-repo.git
npm ERR! error: remote origin already exists.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/runner/.npm/_logs/2022-02-03T04_45_01_401Z-debug.log
Error: Process completed with exit code 3.
I found the issue. My package.json is not updated with the latest changes. which is related to Angular update. I checkout to I pull the mast branch and with my branch and work.

Gitlab - Update version package

We created a vuejs library proyect in Gitlab and created a simple pipelines that excecuted after when we pushed the commit.
We have a problem when last job execute the npm version patch (that update the patch in the project) but... it's not updated and it's doesn't work.
.gutlab-ci.yml
image: node:8.10.0-slim
cache:
paths:
- node_modules/
before_script:
- npm install
stages:
- lint
- test
- deploy
test:
stage: test
script:
- npm run peers:add && npm run test:unit
tags:
- docker
lint:
stage: lint
script:
- npm run lint
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
publish:
stage: deploy
script:
- npm run peers:remove
- echo -e "//gitlab.com/api/v4/projects/<my-project>/packages/npm/:_authToken=${CI_NPM_TOKEN}" > ~/.npmrc
- npm login
- npm version patch
- npm publish
And package.json
[...]
"scripts": {
...
"build:dev": "npm run clean && webpack --config build/webpack.config.dev.js",
"version": "npm run build:dev && git add -A dist",
"postversion": "git push --follow-tags"
...
}
[...]
Jobs lint and test working but the publish not.
[...]
removed 4 packages in 9.428s
$ echo -e "//gitlab.com/api/v4/projects/<my-project>/packages/npm/:_authToken=${CI_NPM_TOKEN}" > ~/.npmrc
$ npm login
Username: npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/...-debug.log
ERROR: Job failed: exit code 1
We need when the Merge Request it's accepted, automatically builed library and upload to npm repository with a new version (new patch, npm version patch). It's possible?
Thx.
npm login is an interactive command so doesn't work in CI very well. Try using the package npm-login-noninteractive to pass your credentials via command line. You can install it globally in your before_script:
before_script:
- npm i -g npm-login-noninteractive
Then call it in place of npm login in your publish script.

ESlint ERROR: Unexpected top-level property "installedESLint"

I am trying to use react-native-web in my college project.
When I lint with ESlit in local, it will be no error. But when the code is running on the Gitlab-CI pipeline, it always show this error when doing lint:
Error: ESLint configuration in /builds/PPL2018csui/Kelas-A/Kel-5/functions/node_modules/grpc/node_modules/uuid/.eslintrc.json is invalid:
- Unexpected top-level property "installedESLint".
I already have my own .eslintrc file, but the ESlint always refer to uuid/.eslintrc.json.
This is my gitlab-ci.yml file:
image: node:8
before_script:
- npm install
cache:
paths:
- node_modules/
stages:
- test
- build
- deploy
test:
stage: test
script:
- npm install -g codecov
- npm run lint
- npm test && codecov --token=<TOKEN>
build:
stage: build
script: ./node_modules/.bin/webpack
deploy_staging:
stage: deploy
script:
- ./node_modules/.bin/webpack --config webpack.config.js
- git remote add heroku https://heroku:<TOKEN>#git.heroku.com/<MY-APP>.git
- git push -f heroku HEAD:master
environment:
name: staging
url: https://<MY-APP>.herokuapp.com/
This is the pipeline result:
Running with gitlab-runner 10.6.0-rc1 (0a9d5de9)
on docker-auto-scale 72989761
Using Docker executor with image node:8 ...
Pulling docker image node:8 ...
Using docker image <DOCKER-IMAGE> for node:8 ...
Running on <RUNNER-CONCURRENT> via <OTHER-RUNNER>...
Cloning repository...
Cloning into '/builds/PPL2018csui/Kelas-A/Kel-5'...
Checking out 4a8b0c7e as group_chat_react...
Skipping Git submodules setup
Checking cache for default...
Downloading cache.zip from <CACHE-URL>
Successfully extracted cache
$ npm install
> uglifyjs-webpack-plugin#0.4.6 postinstall /builds/PPL2018csui/Kelas-A/Kel-5/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 1360 packages in 34.056s
$ npm install -g codecov
/usr/local/bin/codecov -> /usr/local/lib/node_modules/codecov/bin/codecov
+ codecov#3.0.0
added 58 packages in 2.266s
$ npm run lint
> deco#0.0.1 lint /builds/PPL2018csui/Kelas-A/Kel-5
> eslint --ext .js .
ESLint configuration in /builds/PPL2018csui/Kelas-A/Kel-5/functions/node_modules/grpc/node_modules/uuid/.eslintrc.json is invalid:
- Unexpected top-level property "installedESLint".
Error: ESLint configuration in /builds/PPL2018csui/Kelas-A/Kel-5/functions/node_modules/grpc/node_modules/uuid/.eslintrc.json is invalid:
- Unexpected top-level property "installedESLint".
at validateConfigSchema (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config/config-validator.js:221:15)
at Object.validate (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config/config-validator.js:238:5)
at loadFromDisk (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config/config-file.js:516:19)
at Object.load (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config/config-file.js:559:20)
at Config.getLocalConfigHierarchy (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config.js:227:44)
at Config.getConfigHierarchy (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config.js:179:43)
at Config.getConfigVector (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config.js:286:21)
at Config.getConfig (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config.js:329:29)
at processText (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/cli-engine.js:163:33)
at processFile (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/cli-engine.js:224:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! deco#0.0.1 lint: `eslint --ext .js .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the deco#0.0.1 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-03-20T06_38_47_590Z-debug.log
ERROR: Job failed: exit code 1
Is there anyone who can help me with the error?
You can remove the entry "installedESLint:true". It was a bug which put that entry on init as mentioned here

Resources