Github Action - Error: Process completed with exit code - node.js

I am trying to setup Github actions to npm publish my package. But I got this error When I move on execute
My workflows/publish.yml file looks like the following:
name: publish
on:
push:
branches: [ main ]
jobs:
release:
name: publish
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout#v2.3.4
- name: Setup Node.js environment
uses: actions/setup-node#v2.2.0
with:
node-version: 14
registry-url : https://registry.nmpjs.org
- name: publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}

Your package.json file is broken.
{
"name": "#sakibb019/npx-card",
"version": "1.0.0",
"description": "",
"main": "card.js",
"scripts": {
"dev": "nodemon card.js"
},
"keywords": [],
"author": "",
"repository": {
"url": "git://github.com/sakibb019/test.git"
},
"license": "ISC",
"dependencies": {
"boxen": "^5.0.1",
"chalk": "^4.1.1",
"clear": "^0.1.0",
"inquirer": "^8.1.0"
}
}
I've added the missing braces, still, you would need to find a complete package JSON file. There should be more content after "inquirer": "^8.1.

Related

GitHub actions: NPM publish fails with ERR! code ENEEDAUTH

I've attempted to implement the official guide to publishing and installing a package with GitHub Actions: Authenticating to package registries with granular permissions
Fails with:
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://npm.pkg.github.com
npm ERR! need auth You need to authorize this machine using `npm adduser`
package.json
{
"name": "#charneykaye/banana",
"version": "4.0.6",
"repository": "git#github.com:charneykaye/banana",
"description": "made by artists in a new algorithmic medium",
"bin": {
"banana": "./lib/index.js"
},
"author": "Charney Kaye <charney#xj.io>",
"license": "MIT",
"scripts": {
"start": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts",
"start:windows": "nodemon --watch 'src/**/*.ts' --exec \"npx ts-node\" src/index.ts",
"create": "npm run build && npm run test",
"banana": "npx ts-node ./src/index.ts",
"test": "tsc -p . && jest --coverage --verbose --runInBand"
},
"dependencies": {
"commander": "^10.0.0",
"figlet": "^1.5.2",
"octokit": "^1.8.0"
},
"devDependencies": {
"#babel/core": "^7.20.12",
"#babel/preset-env": "^7.20.2",
"#babel/preset-typescript": "^7.18.6",
"#jest/globals": "^29.4.1",
"#types/jest": "^29.4.0",
"#types/node": "^18.11.18",
"babel-jest": "^29.4.1",
"jest": "^29.4.1",
"nodemon": "^2.0.20",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testMatch": [
"**/__tests__/**test.ts",
"**/__tests__/**test.tsx"
]
}
}
.github/workflow/ci.yml
name: "CI Build & Publish"
on:
push:
branches:
- main
jobs:
CI:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup Node.js
uses: actions/setup-node#v3
with:
node-version: 18.14
cache: 'npm'
- name: Install npm packages
run: npm install
- name: Unit tests
run: npm test
- name: Build Banana
run: npm run banana -- --build --env prod
- uses: actions/upload-artifact#v3
with:
name: banana
path: ./build/
- name: Publish NPM package
run: npm publish
.npmrc
#charneykaye:registry=https://npm.pkg.github.com
Needed to do a connect two more dots to get the token all the way to npm publish
Replace .npmrc with
//npm.pkg.github.com/:_authToken=${NPM_CONFIG_TOKEN}
#charneykaye:registry=https://npm.pkg.github.com
always-auth=true
and the last action in .github/workflow/ci.yml with
- name: Publish NPM package
run: npm publish
env:
NPM_CONFIG_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Error: getaddrinfo EAI_AGAIN undefined at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26)

I ran mocha tests in node.js. The following are the details related to it [includes the error]
github actions workflow: default node js github actions
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
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
package.json
{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha ./**/*.test.js --exit",
"dev": "nodemon server.js",
"start": "node server.js",
"debug": "nodemon --inspect=0.0.0.0:9229 server.js"
},
"keywords": [],
"author": "Pragati Bhattad <pragatibhattad1610#gmail.com>",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.18.1",
"express-rate-limit": "^5.2.3",
"express-validator": "^6.14.2",
"jsonpath": "^1.1.1",
"jsonwebtoken": "^8.5.1",
"morgan": "^1.10.0",
"pg": "^8.5.1",
"pg-hstore": "^2.3.3",
"sequelize": "^6.3.5",
"uuid4": "^2.0.2",
"winston": "^3.3.3"
},
"devDependencies": {
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"mocha": "^7.2.0",
"nodemon": "^2.0.6"
}
}
Error:
Error: getaddrinfo EAI_AGAIN undefined
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26)
This error is under each test case
Kindly help me out with this query
The tests use localhost as the url to test on ..I have used the url as http://localhost:8080. If that is what is causing the issue on github actions
The following solutions didn't work for my case
What's the cause of the error 'getaddrinfo EAI_AGAIN'?
https://github.com/fastify/help/issues/592

Unable to debug Node.js application in WebStorm using Serverless

I am currently creating a lambda function in Node.js and want to debug the code locally. I am using WebStorm as my IDE.
In my serverless.yml
service: applicationsync
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs12.x
plugins:
- serverless-offline
functions:
hello:
handler: index.handler
events:
- http:
path: hello
method: get
- http:
path: hello
in my package.json
{
"name": "applicationsync",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "./node_modules/.bin/serverless offline -s dev",
"debug": "set SLS_DEBUG=* && node --inspect /usr/lib/node_modules/serverless/bin/serverless offline -s dev"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"serverless-offline": "^8.8.0"
},
"dependencies": {
"aws-sdk": "^2.1170.0",
"mysql": "^2.18.1"
}
}
And then I have added some screen shots.
I click on debug option:
The following runs:
My file structure:
When I send a request I get a response back but break points are ignored and debug is not triggered.
I am wondering what I am missing.

local debug nodejs aws lambda

I am creating a es6 nodejs lambda using serverless npm package. For using js import feature I added type module in package.json and all my js files are using extension .mjs. Now I am trying to deploy my lambdas in my local using serverless offline, when I execute command
serverless offline -s dev
It seems to deploy my functions and my endpoint. However when I hit that endpoint it shows me that can not find handler module. Specifically it can not find the module define in handler for this endpoint
Cannot find module '/home/leo/Documents/User/technical/core/core-freight-logistics/lambda-js/getlabelbyuser-lambda/handler
This is my serverless.yml
service: label-lambda-inter
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs16.x
plugins:
- serverless-offline
functions:
getLabel:
name: get-label
handler: label-lambda-inter/handler.getLabel
environment: ${file(core.${opt:stage, 'dev'}.json)}
executeQuery:
name: execute-query
handler: execute-query-lambda/handler.executeQuery
environment: ${file(core.${opt:stage, 'dev'}.json)}
getLabelByUserId:
handler: getlabelbyuser-lambda/handler.getLabelByUserId
environment: ${file(core.${opt:stage, 'dev'}.json)}
events:
- http:
path: inter-label/{id}
method: get
cors: true
This is my package.json:
{
"name": "lambda",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "./node_modules/.bin/serverless offline -s dev",
"debug": "export SLS_DEBUG=* && node --inspect /usr/local/bin/serverless offline -s dev"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.1165.0",
"dotenv": "^16.0.1",
"pg-promise": "^10.11.1",
"uuid": "^8.3.2"
},
"devDependencies": {
"serverless-offline": "^8.8.0"
}
}
I am not sure if this is caused by the extension mjs of my handler file. Can someone help me please?
Thanks

How to run jest by lerna in github actions

I am trying to run jest for a monorepo project maintained by lerna in the github actions.
name: Run Unit Test
on:
push:
branches:
- master
- dev
pull_request:
branches:
- master
- dev
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Cache node modules
uses: actions/cache#v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm -v && npm install
- name: Run Unit Test
run: npm run test
- name: Coveralls
uses: coverallsapp/github-action#master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
I got jest: not found error when run test in github actions.
you can see the error logs here. But when I run npm install and npm run test in my own macOs, everything works fine.
and this is my package.json of root:
{
"private": true,
"description": "a progressive micro frontend library",
"workspaces": [
"packages/*"
],
"scripts": {
"postinstall": "lerna bootstrap",
"bootstrap": "lerna bootstrap",
"clean": "lerna clean",
"test": "lerna run test --stream",
"build": "lerna run build --stream",
"commit": "git cz",
"lint": "lerna run lint --stream",
"publish": "lerna publish",
"docs": "docsify serve docs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ObviousJs/obvious.git"
},
"author": "Philip Lau",
"license": "MIT",
"bugs": {
"url": "https://github.com/ObviousJs/obvious/issues"
},
"homepage": "https://github.com/ObviousJs/obvious#readme",
"publishConfig": {
"access": "public"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"devDependencies": {
"#rollup/plugin-commonjs": "20.0.0",
"#rollup/plugin-node-resolve": "13.0.4",
"#typescript-eslint/eslint-plugin": "4.31.0",
"#typescript-eslint/parser": "4.31.0",
"commitizen": "4.2.4",
"cz-conventional-changelog": "3.3.0",
"docsify-cli": "4.4.3",
"eslint": "7.32.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.1.0",
"husky": "4.3.8",
"lerna": "4.0.0",
"rollup": "2.56.3",
"rollup-plugin-typescript2": "0.30.0"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run build && git add ./"
}
}
}
this is the package.json of sub project:
{
"name": "#obvious/core",
"version": "0.4.0",
"description": "a progressive micro front framework",
"main": "./dist/index.umd.js",
"module": "./dist/index.es.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "rollup -c rollup.config.js",
"lint": "eslint --fix --ext .ts,.js test",
"test": "jest --coverage"
},
"author": "Philip Lau",
"license": "MIT",
"dependencies": {
"#vue/reactivity": "3.2.10",
"tslib": "2.3.1"
},
"devDependencies": {
"#types/jest": "27.0.1",
"jest": "27.1.1",
"nock": "13.1.3",
"node-fetch": "2.6.2",
"ts-jest": "27.0.5",
"typescript": "4.4.3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ObviousJs/obvious-core.git"
},
"bugs": {
"url": "https://github.com/ObviousJs/obvious-core/issues"
},
"homepage": "https://github.com/ObviousJs/obvious-core#readme"
}
my github repo address is https://github.com/ObviousJs/obvious-core.
sorry for my pool english but I really need some help (orz
I have zero knowledge about this, but for a temporary answer, what worked for me (when I had the same error with jest) was adding,
- run: lerna bootstrap --no-ci
before running my npm test command in my workflow config. Thus I ended up with a workflow like this:
on:
pull_request:
branches: [ master ]
jobs:
test_pull_request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: 12
# fix issue with lerna and clean installs
- run: lerna bootstrap --no-ci
- run: npm test
I finally solved this problem by setting
useWorkspaces: false
in lerna.json
the reason is that npm6.x doesn't support workspace. And the npm version of github-action runner is just v6, so the workspaces in package.json is useless, so we should set useWorkspaces in lerna.json to false

Resources