Error while building simple API with AWS CodePipeline, CodeBuild - node.js

I have been attempting to set up auto-deploy from my github repo for this simple REST API and cannot get it to stop erroring on 'npm install'. It is your basic node project with express. Here is my buildspec.yml:
version: 0.2
phases:
install:
runtime-versions:
nodejs: 10
commands:
- echo Installing
pre_build:
commands:
- echo Installing source NPM dependencies.
- npm install
build:
commands:
- echo Build started on `date`
- echo Compiling the Node.js code
- npm run build
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- '**/*'
Here is the error prinout from AWS CodeBuild:
[Container] 2022/05/15 21:13:45 Running command npm install
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion#1, but package-lock.json was generated for lockfileVersion#2. I'll try to do my best with it!
npm WARN wts_api#1.0.0 No description
npm WARN wts_api#1.0.0 No repository field.
npm ERR! code EEXIST
npm ERR! path /codebuild/output/src331276253/src/node_modules/.bin/nodemon
npm ERR! Refusing to delete /codebuild/output/src331276253/src/node_modules/.bin/nodemon: is outside /codebuild/output/src331276253/src/node_modules/nodemon and not a link
npm ERR! File exists: /codebuild/output/src331276253/src/node_modules/.bin/nodemon
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-05-15T21_13_48_178Z-debug.log
[Container] 2022/05/15 21:13:48 Command did not exit successfully npm install exit status 1
[Container] 2022/05/15 21:13:48 Phase complete: PRE_BUILD State: FAILED
[Container] 2022/05/15 21:13:48 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm install. Reason: exit status 1
I think I've done this 100% as convention dictates, except for maybe my project structure. Rather than having all my files in 'src', they are in the root of the project.

Maybe you found the answer already, but for future readers, here it goes:
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion#1, but package-lock.json was generated for lockfileVersion#2. I'll try to do my best with it!
According to this message, the reason why the install fails is because you used different versions of npm on local machine vs on codebuild.
Your codebuild is using nodejs: 10 runtime, so according to the screenshot below (taken from https://nodejs.org/en/download/releases/), it must be using npm v6.8.x that comes with that version of node.
That version of npm generates/reads package-lock.json file with a version 1 format, while your local npm has generated a package-lock.json with the version 2 format, most certainly because you are on npm v7 or later.
Solution:
Update npm version in the pre-build phase of your Codebuild, as such:
pre_build:
commands:
- echo Installing source NPM dependencies.
- npm install -g npm#<your_local_version_here>
- npm ci
Also, it better to use npm ci rather than npm install on CI, because the former leverage the existing package-lock.json to ensure reproductible builds.

Related

Angular dependency errors, during pipeline

The following chain of events had occured.
The Angular website application was pretty outdated, possibly v3 and was upgraded to 8.2.8, couldnt go all the way due to a dependency on mdbbootstrap which would require a rewrite in many places, made a change and the pipeline and check completed.
Coming back from another project i ran into this problem Angular project produces javascript error "core.js:23018 Uncaught TypeError: Cannot read properties of undefined (reading 'id')", which was solved by npm -ci
Now after making my current changes, and sending off to gitlab pipeline, the following errors occur
npm ERR! While resolving: angular-date-value-accessor#0.0.1
npm ERR! Found: #angular/core#8.2.14
npm ERR! node_modules/#angular/core
npm ERR! #angular/core#"~8.2.8" from the root project
npm ERR! peer #angular/core#"8.2.14" from #angular/animations#8.2.14
npm ERR! node_modules/#angular/animations
npm ERR! #angular/animations#"~8.2.8" from the root project
npm ERR! peer #angular/animations#">=6.0.0 <9.0.0" from angular-calendar#0.26.11
npm ERR! node_modules/angular-calendar
npm ERR! angular-calendar#"^0.26.11" from the root project
npm ERR! 23 more (#angular/common, #angular/forms, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer #angular/core#"^2.0.0" from angular-date-value-accessor#0.0.1
npm ERR! node_modules/angular-date-value-accessor
npm ERR! angular-date-value-accessor#"0.0.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: #angular/core#2.4.10
npm ERR! node_modules/#angular/core
npm ERR! peer #angular/core#"^2.0.0" from angular-date-value-accessor#0.0.1
npm ERR! node_modules/angular-date-value-accessor
npm ERR! angular-date-value-accessor#"0.0.1" from the root project
this is the gitlab-ci yaml
stage: build_staging
image: node:lts
script:
- grep -rli '%COMMIT_HASH%' * | xargs -i# sed -i "s/%COMMIT_HASH%/$CI_COMMIT_SHORT_SHA/g" #
- cd src/Web
- npm install
- npm run buildstaging
artifacts:
paths:
- src/Web/dist/
name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
only:
refs:
- develop
Deploy Web Staging:
stage: deploy_staging
image: xueshanf/awscli
script:
- cd src/Web
- aws s3 sync ./dist s3://$STAGING_BUCKET_NAME/ --delete
- echo "Invalidate index.html"
- aws cloudfront create-invalidation --distribution-id $STAGING_DISTRIBUTION_ID --paths /index.html
only:
refs:
- develop
(fyi its the build_staging that is the problem)
I am assuming what was fixed on my local machine is now no longer valid for npm install on npm:lts
What would be the proper course of direction, is it as simple as
npm ci( a very demanding operation) instead of npm install ? or git clean ?
I also noticed, although everything works fine locally
in package.json and lock it has
"#angular/core": "~8.2.8",
but in my node_modules it has 8.2.14 in /#angular/core/
after running npm ci
ok here is what i did to get it working. This would not be a problem if ng commands would work so it could auto resolve dependency problems. Each problem gitlab complained about i manually uninstalled and installed to see the error, and its dependency issue. I upgraded either the component or dependency. until all were gone. Some components had to go completely, but none required a re-code of any usage (i think so far, it hasnt been fully tested).
Now when i finally resolved all these issues, i would get errors such as this
npm ERR! path /builds/0/WebSites/customerportal/CustomerPortal/src/Web/node_modules/node-sass
npm ERR! command failed
npm ERR! command sh -c node scripts/build.js
npm ERR! Building: /usr/local/bin/node /builds/0/WebSites/customerportal/CustomerPortal/src/Web/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
allot more all pointing to gyp, and some problem with python version.
I changed the version of the image to Node:14 in the yaml file, and the building stage would complete. Also, the deploy stage would complete, (but the C# api layers time out on warning: 8 tasks failed to start

Cypress installation failed

I installed nodejs and npm on windows 10. Than I tried to install cypress via npm install cypress --save-dev and get the following Error:
> node index.js --exec install
The command "node" is either misspelled or
could not be found.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cypress#3.8.2 postinstall: `node index.js --exec install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cypress#3.8.2 postinstall 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! C:\Users\U\AppData\Roaming\npm-cache\_logs\2020-01-21T11_05_01_566Z-debug.log
After this I added the path %USERPROFILE%\AppData\Local\Temp to my system environment variables. But I get this error messages again. How can I fix this problem?
try the following steps :
install git on your machine and config it as global.
delete old package.js then re-init new package.
try again cypress install command
Try this instead by installing the previous version but Explicitly: npm install cypress#8.1.0 --save-dev
Download it in the any directory its a hack to download, if your proxy is properly configured and internet speed is good. it will download while doing npm install
wget https://cdn.cypress.io/desktop/7.6.0/win32-x64/cypress.zip
Provide the zip location
CYPRESS_INSTALL_BINARY=~/Downloads/cypress.zip npm install cypress
Remember to actually run the npm command inside your folder with the package.json.
Delete the package.json.
Again re build the package by npm init.
Install Cypress again by using npm install cypress --save-dev.

How to start project node.js error with name

I need start the project https://github.com/oracle/bots-node-sdk and I don`t know a lot of node.js. I try follow the instructions, but I receive the errors.
npm install #oracle/bots-node-sdk
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "#oracle/bots-node-sdk" under a package
npm ERR! also called "#oracle/bots-node-sdk". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
npm ERR! <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\josiv\AppData\Roaming\npm-cache\_logs\2019-02-05T16_16_57_042Z-debug.log
I already try change name in file package.json and also I try command: npm init "other_name" and always the same error.
Edit:
I change name in file package.json and run npm install #oracle/bots-node-sdk. After run npx #oracle/bots-node-sdk init with successful:
---------------------------------------------------------------------
Custom Component package 'bots-node-sdk-master' created successfully!
---------------------------------------------------------------------
Usage:
npm start Start a dev server with the component package
PS D:\Fontes\OracleDigitalAssistant-Bot\bots-node-sdk-master> npm start
> bots#2.1.3 start D:\Fontes\OracleDigitalAssistant-Bot\bots-node-sdk-master
> npm run bots-node-sdk -- --service .
> bots#2.1.3 bots-node-sdk D:\Fontes\OracleDigitalAssistant-Bot\bots-node-sdk-master
> bots-node-sdk "--service" "."
It is saying there's a conflict with your project name and the dependency you're trying to install.
In your package.json, if the name property is "#oracle/bots-node-sdk" then change it to someone else and then run npm install #oracle/bots-node-sdk again.
Alternatively you can just delete the package.json file and then run npm init -y.

npm i Running command - failed! (exit code 254)

Ionic :3.20.0
node: v8.10.0
npm: 5.6.0
npm i
✖ Running command - failed!
[ERROR] An error occurred while running npm i (exit code 254):
npm ERR! path
/Users/lucaszimmermann/Desktop/myApp/node_modules/tsickle/src/main.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod
'/Users/lucaszimmermann/Desktop/myApp/node_modules/tsickle/src/main.js'
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!
/Users/lucaszimmermann/.npm/_logs/2018-04-04T16_41_39_270Z-debug.log
I faced a similar issue after doing the below actions this issue solved.
Delete package-lock.json file.
Open cmd/terminal in administrator mode.
run command: npm install
run command: npm update
Node version is likely incompatible. There'd be an expected version actual version. Use nvm or similar to install and change node versions.
Delete node_modules and try install again. You probably get a message similar to:
error ts-jest#26.1.2: The engine "node" is incompatible with this module. Expected version ">= 10.21.0". Got "10.20.1"
error Found incompatible module.
You wan't try to install npm packages.
You have two options to install some packages:
First Option:
npm install <package>
npm i <package>
Second Option:
If you wan't to create an automated installation process without each package, you must provide an packge.json - Here are all depencies listed. You can only run npm i or npm install without an package name, if you have an package.json
A full documentation about that is on NPM: https://docs.npmjs.com/files/package.json

Installing bootstrap with npm is failing

I am attempting to install bootstrap (LESS) with npm on Debian but it keeps failing.
This is exactly what i am doing:
git clone https://github.com/twbs/bootstrap.git
npm install
The error i get is simply Killed.
Running the npm install in verbose i do not get any error:
npm verb readDependencies using package.json deps
npm http GET https://registry.npmjs.org/postcss/-/postcss-2.2.5.tgz
npm info retry fetch attempt 1 at 01:00:50
npm verb fetch to= /tmp/npm-3690-Rr0nZSRK/registry.npmjs.org/caniuse-db/-/caniuse-db-1.0.30000010.tgz
npm info postinstall ansi-regex#0.2.1
Killed
npm install
simply installs the upstream dependencies based on what is listed in the package.json in your current directory
Try this
git clone https://github.com/twbs/bootstrap.git
cd bootstrap
npm install # installs dependencies
npm install -g bootstrap # does actual install of bootstrap into module dir
note the -g in the install command puts bootstrap into your global npm module directory
as defined by environment variable $NODE_PATH
You can also low down memory consumption by "npm config set jobs 1", did work for me ;) link: https://community.c9.io/t/npm-install-is-killed/847

Resources