Angular dependency errors, during pipeline - node.js

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

Related

How to fix npm Err ERESOLVE peer depandencies for ReactJS for Vercel Hosting deployment

Synopsis
After about a month of working, I could deploy my project. I cloned the folder (just in case) and used Git to upload it to my GitHub Repository. I then logged onto Vercel's Hosting, chose their free hobby pricing (the free one) and connected my Github account to which I uploaded my portfolio. I then pressed 'deploy' and received an error that started with "npm Err code ERESOLVE" please look at the section marked an error. After about 2-3 hours of researching and Stack Overflow looking, I could find an answer.
Context
After completing my month-long project on VS Code, I decided to clone the folder and remove everything inside the directory outside. This means that I originally had my VScode folder and another folder that npx created (Image 1). However, to upload it to Github, I removed it from the following folder created and put it in the main outside folder (See image 2). Then I downloaded Git (checked it using its version) and uploaded my copied folder to a GitHub Repo called portfolio-new (check marked Github repo below). Once I was done, I headed to Vercel, a hosting platform, and decided to host my react project there. Vehicle integration makes it, so they run their npm start on their platform. Therefore I have no control over the deployment after I press 'deploy.' After pressing deploy, I received an error of dependencies (see error below).
Problem
To recap, as mentioned above, the problem is that Vercel is its system, and I cannot control how it does npm start (you will see why that is important). Therefore when it runs, it is an error. It means I must fix the code, not how I run it.
Why not use --force or --legacy-peer-deps
The issue with this is that Vercel's system needs to let me control its commands. Therefore, I cannot use either of these commands to make it force to run. That means the answer that shall be posted must fix the actual error instead of having a temporary go-around. Again to repeat, I CANNOT use these two commands!
[13:28:58.885] Cloning github.com/Abdjsjiski/portfolio-new (Branch: main, Commit: 5f53564)
[13:28:58.889] Skipping build cache since Vercel CLI used --force option
[13:28:59.634] Cloning completed: 748.787ms
[13:29:00.056] Running "vercel build"
[13:29:00.521] Vercel CLI 28.10.0
[13:29:01.088] Installing dependencies...
[13:29:02.759] npm ERR! code ERESOLVE
[13:29:02.775] npm ERR! ERESOLVE could not resolve
[13:29:02.775] npm ERR!
[13:29:02.775] npm ERR! While resolving: react-notifications-menu#1.0.6
[13:29:02.776] npm ERR! Found: react#18.2.0
[13:29:02.776] npm ERR! node_modules/react
[13:29:02.776] npm ERR! react#"^18.2.0" from the root project
[13:29:02.776] npm ERR! peer react#">=16.8.0" from #emotion/react#11.10.5
[13:29:02.776] npm ERR! node_modules/#emotion/react
[13:29:02.776] npm ERR! #emotion/react#"^11.10.5" from the root project
[13:29:02.776] npm ERR! peer #emotion/react#"^11.0.0-rc.0" from #emotion/styled#11.10.5
[13:29:02.776] npm ERR! node_modules/#emotion/styled
[13:29:02.776] npm ERR! #emotion/styled#"^11.10.5" from the root project
[13:29:02.776] npm ERR! 3 more (#mui/material, #mui/styled-engine, #mui/system)
[13:29:02.776] npm ERR! 3 more (#mui/material, #mui/styled-engine, #mui/system)
[13:29:02.776] npm ERR! 41 more (#emotion/styled, ...)
[13:29:02.777] npm ERR!
[13:29:02.777] npm ERR! Could not resolve dependency:
[13:29:02.777] npm ERR! peer react#"^15.0.0 || ^16.0.0" from react-notifications-menu#1.0.6
[13:29:02.777] npm ERR! node_modules/react-notifications-menu
[13:29:02.777] npm ERR! react-notifications-menu#"^1.0.6" from the root project
[13:29:02.777] npm ERR!
[13:29:02.777] npm ERR! Conflicting peer dependency: react#16.14.0
[13:29:02.777] npm ERR! node_modules/react
[13:29:02.777] npm ERR! peer react#"^15.0.0 || ^16.0.0" from react-notifications-menu#1.0.6
[13:29:02.777] npm ERR! node_modules/react-notifications-menu
[13:29:02.777] npm ERR! react-notifications-menu#"^1.0.6" from the root project
[13:29:02.777] npm ERR!
[13:29:02.778] npm ERR! Fix the upstream dependency conflict, or retry
[13:29:02.778] npm ERR! this command with --force, or --legacy-peer-deps
[13:29:02.778] npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
[13:29:02.778] npm ERR!
[13:29:02.778] npm ERR! See /vercel/.npm/eresolve-report.txt for a full report.
[13:29:02.778]
[13:29:02.778] npm ERR! A complete log of this run can be found in:
[13:29:02.778] npm ERR! /vercel/.npm/_logs/2022-12-31T18_29_01_308Z-debug-0.log
[13:29:02.796] Error: Command "npm install" exited with 1
Github Repo
If it isnt obvious by now i am using only pure ReactJS
Before I clone the folder
After the cloned folder and put everything outside
i am aware there are many similar questions to mine but mine has more to do with how to fix the actual problem then the other temporary go arounds + how to deploy it properly instead of leaving it on Vercel
Before posting, I did some research which included the following:
Using the --force or -- legacy-peer-deps command anyway
Removing node modules and package-lock.json and doing the npm install
Removing cache with force
Audit fix -- force and audit fix normal
npm fund
Re-installing / updating ALL my dependencies with force
Updating react scripts
Using -- save and retrying all commands
None of these worked. I updated my GitHub repo to the newest version, redeployed it, and got the same error.
Why does your problem differ from others
It's mostly not related to the code but to the hosting platform therefore the normal answers wont work such as the above given but to fix the problem you need to fix the code itself
Ok, I found an answer after three more hours of searching!!
In Vercel, go to the change command lines and look for npm install or yarn install
Note this is more of a workaround ironic to my question but It sufficed
You can then change the command to npm install --force and it will deploy but I would still be really glad if anyone could fix the actual problem that occured

Error while building simple API with AWS CodePipeline, CodeBuild

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.

Issue with git dependency on node version upgrade

I am running a VUE.JS app in a Docker container. The app is currently using node 14.19.0, but I tried upgrading the version to node 15/16.
After changing the node version in the Dockerfile and updating some of the devDependencies, I get an NPM error:
npm ERR! npm ERR! An unknown git error occurred
npm ERR! npm ERR! command git --no-replace-objects ls-remote ssh://git#github.com/[NAMESPACE_PLACEHOLDER]/[REPO_PLACEHOLDER].git
npm ERR! npm ERR! Warning: Permanently added 'github.com' (ECDSA) to the list of known hosts.
npm ERR! npm ERR! git#github.com: Permission denied (publickey).
npm ERR! npm ERR! fatal: Could not read from remote repository.
npm ERR! npm ERR!
npm ERR! npm ERR! Please make sure you have the correct access rights
npm ERR! npm ERR! and the repository exists.
In my package.json file, the repo is loaded with https, not ssh:
"package-name-placeholder": "https://github.com/[NAMESPACE_PLACEHOLDER]/[REPO_PLACEHOLDER].git#v0.1.15"
This exact method is working with Node 14.19.0. I read that there might be an issue with trailing slashes. I tried using them, but the error persists.
Have anyone managed to do something about a similar issue?
Thanks.
Try in your Dockerfile a:
RUN git config --global url."https://${GIT_ACCESS_TOKEN}#github.com".insteadOf "ssh://git#github.com"
(If those repositories are public, you do not need the ${GIT_ACCESS_TOKEN}# part: it would be an ARG GIT_ACCESS_TOKEN passed with a docker build --build-arg GIT_ACCESS_TOKEN=xxx)
You can see here this was reported before:
npm version change in alpine-16's image, and I'm pretty sure that this problem is related to npm version.

Unable to resolve dependencies for Angular Universal

I need to use SSR for one of my existing angular project. For that, I have migrated one of my projects from v8 to v13.0.0, which itself took a lot of time.
HOwever, now that the app is running fine on v13.0.0, I tried adding SSR to it using
ng add #nguniversal/express-engine
This commands seems to add 13.0.1 of universal, but it keeps failing with errors similar to below one:
D:\my-app-universal>ng add #nguniversal/express-engine i Using package
manager: npm √ Found compatible package version:
#nguniversal/express-engine#13.0.1. √ Package information loaded.
The package #nguniversal/express-engine#13.0.1 will be installed and
executed. Would you like to proceed? Yes npm ERR! code ERESOLVE npm
ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR!
While resolving: my-app-universal#0.0.0 npm ERR! Found:
#angular/animations#13.0.3 npm ERR! node_modules/#angular/animations
npm ERR! #angular/animations#"~13.0.0" from the root project npm
ERR! npm ERR! Could not resolve dependency: npm ERR! peer
#angular/animations#"13.2.3" from #angular/platform-server#13.2.3 npm
ERR! node_modules/#angular/platform-server npm ERR! peer
#angular/platform-server#"^13.0.1" from
#nguniversal/express-engine#13.0.1 npm ERR!
node_modules/#nguniversal/express-engine npm ERR!
#nguniversal/express-engine#"13.0.1" from the root project npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this
command with --force, or --legacy-peer-deps npm ERR! to accept an
incorrect (and potentially broken) dependency resolution. npm ERR! npm
ERR! See
C:\Users\saurabhtiwari\AppData\Local\npm-cache\eresolve-report.txt for
a full report.
npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\saurabhtiwari\AppData\Local\npm-cache_logs\2022-02-20T12_03_46_821Z-debug.log
× Package install failed, see above.
I have tried a lot to read through the errors and updating package.json to match the required version of peers but it just doesn't go away.
Is there a systematic way to resolve these errors.
Is there a particular version of universal that might go well with Angular 13.
Any suggestions are welcomed.
I followed #misha130's comments advice and fixed the version numbers. I didn't need to need to install with --legacy-peer-deps or --force.
The solution was to upgrade #angular/cli & #angular/core.
With a fresh install, my initial version was 13.0.4. You will need to upgrade them one at a time as the update command fails if there are staged and uncommitted changes in the repository.
ng update #angular/cli
git add . && git commit -m 'nguniversal fix 1 - update #angular/cli'
ng update #angular/core
git add . && git commit -m 'nguniversal fix 2 - update #angular/core'
ng add #nguniversal/express-engine
Thanks everyone for their inputs in the comment. I figured it out as below.
As suggested in comments, first I installed the universal package using --legacy --per --deps
npm install #nguniversal/express-engine --save --legacy-peer-deps
This installed the packages in the node_modules, although the required express-server related files were not added.
To add those files, I then ran:
ng add #nguniversal/express-engine
This creates the required file. It will also try to install the package again and will fail in doing so. Since the package have been installed already, I guess you can ignore its error.

npm install -g dredd#stable fails on CircleCI due to npm ERR! code ECONNRESET

I have a project on CircleCI which started going red (due to failure on installing dredd) at some point. Currently the same exact project (same code, same circle.yml) may fail or succeed at random it seems.
The failure is always in the phase npm install -g dredd#stable with the following error which repeats itself several times and eventually fails the build:
make: Leaving directory /opt/circleci/nodejs/v4.2.6/lib/node_modules/dredd/node_modules/dredd-transactions/node_modules/fury-adapter-apib-parser/node_modules/drafter/node_modules/protagonist/build'
npm ERR! Linux 3.13.0-117-generic
npm ERR! argv "/opt/circleci/nodejs/v4.2.6/bin/node" "/opt/circleci/nodejs/v4.2.6/bin/npm" "install" "-g" "dredd#stable"
npm ERR! node v4.2.6
npm ERR! npm v2.14.12
npm ERR! code ECONNRESET
npm ERR! errno ECONNRESET
npm ERR! syscall read
npm ERR! network read ECONNRESET
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
If I try to rerun the build several times it will succeed at some point (going Green). The dredd installation then shows up something like this:
make: Leaving directory /opt/circleci/nodejs/v4.2.6/lib/node_modules/dredd/node_modules/dredd-transactions/node_modules/fury-adapter-apib-parser/node_modules/drafter/node_modules/protagonist/build'
/opt/circleci/nodejs/v4.2.6/bin/dredd -> /opt/circleci/nodejs/v4.2.6/lib/node_modules/dredd/bin/dredd
dredd#3.4.5 /opt/circleci/nodejs/v4.2.6/lib/node_modules/dredd
├── caseless#0.12.0
├── clone#2.1.1
├── file#0.2.2
etc', basically installing dredd successfully and moving on to test the build.
Since it seems to fail randomly I don't think the proxy has anything to do with it. Here is the circle.yml file for reference:
machine:
environment:
APIARY_API_KEY: "123456789ab12cd1234a1a1a123a123a"
ruby:
version: 2.3.1
dependencies:
pre:
- npm install -g dredd#stable
- gem install apiaryio
- pip install dredd_hooks
database:
override:
- bundle exec rake db:create db:schema:load db:seed
test:
pre:
- apiary fetch --api-name=ourAPIName --output=api-description.yml
- dredd
Any help would be most welcome.
I've run into the same issue. One fix I found was to change the registry for npm to use HTTP instead of HTTPS. In my circle.yml file I changed my dependencies from:
dependencies:
pre:
- npm install -g dredd#4.1.1
to
dependencies:
pre:
- npm config set registry http://registry.npmjs.org/
- npm install -g dredd#4.1.1

Resources