Upgrading Angular solution from v11.0.5 to v15.0.5 - node.js

TL;DR: What is the fastest way to upgrade a legacy Angular (eg v11) to the latest version (eg v15)?
I have an Angular 11 solution which has this packages.json file:
{
"name": "my-first-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^11.0.5",
"#angular/common": "^11.0.5",
"#angular/compiler": "^11.0.5",
"#angular/core": "^11.0.5",
"#angular/forms": "^11.0.5",
"#angular/platform-browser": "^11.0.5",
"#angular/platform-browser-dynamic": "^11.0.5",
"#angular/router": "^11.0.5",
"bootstrap": "3.3.7",
"rxjs": "^6.6.3",
"rxjs-compat": "^6.0.0",
"tslib": "^2.0.3",
"zone.js": "^0.10.3"
},
"devDependencies": {
"#angular-devkit/build-angular": "^0.1100.4",
"#angular/cli": "^11.0.4",
"#angular/compiler-cli": "^11.0.5",
"#types/jasmine": "~3.6.0",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.19.9",
"codelyzer": "^6.0.1",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.4",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2"
}
}
npm install in the solution folder produces this:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-first-app#0.0.0
npm ERR! Found: jasmine-core#3.6.0
npm ERR! node_modules/jasmine-core
npm ERR! dev jasmine-core#"~3.6.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core#">=3.8" from karma-jasmine-html-reporter#1.7.0
npm ERR! node_modules/karma-jasmine-html-reporter
npm ERR! dev karma-jasmine-html-reporter#"^1.5.4" 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!
npm ERR! For a full report see:
npm ERR! C:\Users\xxx\AppData\Local\npm-cache\_logs\2023-01-25T20_36_55_645Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xxx\AppData\Local\npm-cache\_logs\2023-01-25T20_36_55_645Z-debug-0.log
I then run npm install --legacy-peer-deps, which produces a lot of WARN statements and then shows this:
added 1597 packages, and audited 1598 packages in 1m
118 packages are looking for funding
run `npm fund` for details
27 vulnerabilities (5 moderate, 21 high, 1 critical)
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
So, I run npm audit fix --force which produces this:
added 143 packages, removed 694 packages, changed 122 packages, and audited 1047 packages in 20s
86 packages are looking for funding
run `npm fund` for details
# npm audit report
minimatch <3.0.5
Severity: high
minimatch ReDoS vulnerability - https://github.com/advisories/GHSA-f8q6-p94x-37v3
fix available via `npm audit fix`
node_modules/minimatch
1 high severity vulnerability
To address all issues, run:
npm audit fix
So, I run npm audit fix --force again, and it shows this:
removed 1 package, changed 1 package, and audited 1046 packages in 3s
86 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Now, if I run ng serve I get this:
Your global Angular CLI version (15.0.5) is greater than your local version (11.1.2). The local Angular CLI version is used.
To disable this warning use "ng config -g cli.warnings.versionMismatch false".
This version of CLI is only compatible with Angular versions ^15.0.0,
but Angular version 11.2.14 was found instead.
Please visit the link below to find instructions on how to update Angular.
https://update.angular.io/
I visit https://update.angular.io/ and select from v11 to v12, as it also states
You can't run ng update to update Angular applications more than one
major version at a time.
So, from https://update.angular.io/?v=11.0-12.0 I run ng update #angular/core#12 #angular/cli#12, which produces:
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 12.2.18 to perform the update.
√ Packages successfully installed.
Using package manager: 'npm'
Collecting installed dependencies...
Found 31 dependencies.
Fetching dependency metadata from registry...
Package "#angular-devkit/build-angular" has an incompatible peer dependency to "#angular/compiler-cli" (requires "^15.0.0" (extended), would install "12.2.17").
Package "#angular-devkit/build-angular" has an incompatible peer dependency to "typescript" (requires ">=4.8.2 <5.0", would install "4.3.5").
× Migration failed: Incompatible peer dependencies found.
Peer dependency warnings when installing dependencies means that those dependencies might not work correctly together.
You can use the '--force' option to ignore incompatible peer dependencies and instead address these warnings later.
See "C:\Users\xxx\AppData\Local\Temp\ng-7soZ7i\angular-errors.log" for further details.
So I run ng update #angular/core#12 #angular/cli#12 --force which produces a lot of output, but appears to work.
Next, I moved to https://update.angular.io/?v=12.0-13.0 which states I should run ng update #angular/core#13 #angular/cli#13 and produces:
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 13.3.10 to perform the update.
√ Packages successfully installed.
Using package manager: 'npm'
Collecting installed dependencies...
Found 31 dependencies.
Fetching dependency metadata from registry...
Package "#angular-devkit/build-angular" has an incompatible peer dependency to "#angular/compiler-cli" (requires "^15.0.0" (extended), would install "13.3.12").
Package "#angular-devkit/build-angular" has an incompatible peer dependency to "typescript" (requires ">=4.8.2 <5.0", would install "4.6.4").
× Migration failed: Incompatible peer dependencies found.
Peer dependency warnings when installing dependencies means that those dependencies might not work correctly together.
You can use the '--force' option to ignore incompatible peer dependencies and instead address these warnings later.
See "C:\Users\xxx\AppData\Local\Temp\ng-p47IAP\angular-errors.log" for further details.
So I run it like this: ng update #angular/core#13 #angular/cli#13 --force which also produces a lot of output but finally appears to complete successfully.
This moves me to https://update.angular.io/?v=13.0-14.0 which states I should run ng update #angular/core#14 #angular/cli#14. I see this:
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 14.2.10 to perform the update.
√ Packages successfully installed.
Using package manager: npm
Collecting installed dependencies...
Found 31 dependencies.
Fetching dependency metadata from registry...
Package "#angular-devkit/build-angular" has an incompatible peer dependency to "#angular/compiler-cli" (requires "^15.0.0" (extended), would install "14.2.12").
× Migration failed: Incompatible peer dependencies found.
Peer dependency warnings when installing dependencies means that those dependencies might not work correctly together.
You can use the '--force' option to ignore incompatible peer dependencies and instead address these warnings later.
See "C:\Users\xxx\AppData\Local\Temp\ng-wQ5M5Z\angular-errors.log" for further details.
So I run ng update #angular/core#14 #angular/cli#14 --force which, again, appears to complete successfully.
This leads me to https://update.angular.io/?v=14.0-15.0 and running the command ng update #angular/core#15 #angular/cli#15 which appears to complete, as well - fortunately, this time, without the need for --force.
Running ng serve works.
Is this the best way to upgrade a legacy Angular project to the latest version?

Yes, the ng update command is the recommended path to update angular applications.
With the latest CLI Versions, you can update only one version at a time (in the past, you could bump two or more versions at once). The idea behind this is to be able to run all the needed migrations when updating to a newer version without the risk of conflicts. The CLI runs the migrations for you.
The errors you got, like:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-first-app#0.0.0
npm ERR! Found: jasmine-core#3.6.0
npm ERR! node_modules/jasmine-core
npm ERR! dev jasmine-core#"~3.6.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core#">=3.8" from karma-jasmine-html-reporter#1.7.0
npm ERR! node_modules/karma-jasmine-html-reporter
npm ERR! dev karma-jasmine-html-reporter#"^1.5.4" from the root project
Are not related to Angular, but to npm (I guess you are using npm 7+). Newer npm versions will check that peer dependencies versions are respected and throw an error in case of a wrong version (as you are getting). From npm 7 release docs:
npm 7 will block installations if an upstream dependency conflict is
present that cannot be automatically resolved.
You have the option to retry with --force to bypass the conflict or
--legacy-peer-deps command to ignore peer dependencies entirely (this behavior is similar to versions 4-6).
In general, I would advise avoiding using --force while updating your dependencies and trying to find the right combination of versions between the libraries.

Related

Angular dependency issue Windows to Linux

I'm trying to host an Angular application for a customer, but I can't get it to run on Linux. The customer develops on Windows and it works for him. I am using NodeJS 19.
Error message when npm install:
npm notice
npm notice New minor version of npm available! 9.2.0 -> 9.3.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.3.1>
npm notice Run `npm install -g npm#9.3.1` to update!
npm notice
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: #agm/core#3.0.0-beta.0
npm ERR! Found: #angular/common#14.2.12
npm ERR! node_modules/#angular/common
npm ERR! #angular/common#"^14.2.0" from the root project
npm ERR! peer #angular/common#"^14.0.0 || ^15.0.0" from #angular/cdk#14.2.7
npm ERR! node_modules/#angular/cdk
npm ERR! #angular/cdk#"^14.2.4" from the root project
npm ERR! peer #angular/cdk#"14.2.7" from #angular/material#14.2.7
npm ERR! node_modules/#angular/material
npm ERR! #angular/material#"^14.2.4" from the root project
npm ERR! 1 more (#angular/material-moment-adapter)
npm ERR! 5 more (#angular/forms, #angular/material, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer #angular/common#"^9.1.0 || ^10.0.0" from #agm/core#3.0.0-beta.0
npm ERR! node_modules/#agm/core
npm ERR! #agm/core#"^3.0.0-beta.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: #angular/common#10.2.5
npm ERR! node_modules/#angular/common
npm ERR! peer #angular/common#"^9.1.0 || ^10.0.0" from #agm/core#3.0.0-beta.0
npm ERR! node_modules/#agm/core
npm ERR! #agm/core#"^3.0.0-beta.0" 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.
package.json
{
"name": "web-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"#agm/core": "^3.0.0-beta.0",
"#angular/animations": "^14.2.0",
"#angular/cdk": "^14.2.4",
"#angular/common": "^14.2.0",
"#angular/compiler": "^14.2.0",
"#angular/core": "^14.2.0",
"#angular/forms": "^14.2.10",
"#angular/material": "^14.2.4",
"#angular/material-moment-adapter": "^14.2.5",
"#angular/platform-browser": "^14.2.10",
"#angular/platform-browser-dynamic": "^14.2.0",
"#angular/router": "^14.2.10",
"#manekinekko/angular-web-bluetooth": "^11.2.2",
"#types/googlemaps": "^3.39.13",
"#types/maplibre-gl": "^1.14.0",
"#types/web-bluetooth": "^0.0.16",
"bootstrap": "^3.4.1",
"maplibre-gl": "^1.15.3",
"moment": "^2.29.4",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "^14.2.2",
"#angular/cli": "~14.2.2",
"#angular/compiler-cli": "^14.2.0",
"#types/geojson": "^7946.0.10",
"#types/jasmine": "~4.0.0",
"jasmine-core": "~4.3.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~4.7.2"
}
}
I have already tried --force and --legacy-peer-deps but it still doesn't work.
A couple of things here.
First one of the packages you're using doesn't like the version of Angular you're using.
#agm/core#3.0.0-beta.0
This says that #agm/core#3.0.0-beta.0 is made for angular 9-10 and you're running 14.
npm ERR! Could not resolve dependency:
npm ERR! peer #angular/common#"^9.1.0 || ^10.0.0" from #agm/core#3.0.0-beta.0
npm ERR! node_modules/#agm/core
npm ERR! #agm/core#"^3.0.0-beta.0" from the root project
If you MUST use this version of #agm/core#3.0.0-beta.0 then you can run:
npm install --legacy-peer-deps
But this is not best practice. It's better to look for a version that works with your Angular version. A quick look at that package (npm view #agm/core versions --json) shows me that you have the latest version, since it's dependency is Angular 9-10 you might want to look for a replacement library that works with your version of Angular.
Second, you are using a development version of node, meaning that 19 is the latest but not considered stable by node.js- odd numbers for development, even numbers for production, current stable version is 18.13.0:
https://nodejs.org/en/download/
If you want to use multiple versions of node, you can use nvm (Node version manager)
Your version of node.js needs to match the installation version of node.js - so the Windows machine and the Linux machine need to both have the same version of node.js - that might be why it works in one place and not the other.

Upgrade from Angular 11 to 12 causes peer dependency conflict

I'm currently upgrading from Angular 11.2.14 to Angular 12.0.5 and I run into the following issue:
npm ERR! Could not resolve dependency:
npm ERR! dev #angular-devkit/build-angular#"12.0.5" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: #angular/compiler-cli#12.0.5
npm ERR! node_modules/#angular/compiler-cli
npm ERR! dev #angular/compiler-cli#"12.0.5" from the root project
npm ERR! peer #angular/compiler-cli#"^12.0.0" from #angular-devkit/build-angular#12.0.5
npm ERR! node_modules/#angular-devkit/build-angular
npm ERR! dev #angular-devkit/build-angular#"12.0.5" from the root project
npm ERR! 2 more (#angular/localize, ng-packagr)
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.
Am I right assuming this is because there is a conflict between the version 12.0.5 and 12.0.0 and they are incompatible? All my dependencies have now the same version, why is there a conflict present?
package.json
"#angular-builders/custom-webpack": "12.1.0",
"#angular-devkit/build-angular": "12.0.5",
"#angular/animations": "12.0.5",
"#angular/cdk": "12.0.5",
"#angular/cli": "12.0.5",
"#angular/common": "12.0.5",
"#angular/compiler": "12.0.5",
"#angular/compiler-cli": "12.0.5",
"#angular/core": "12.0.5",
"#angular/flex-layout": "11.0.0-beta.33",
"#angular/forms": "12.0.5",
"#angular/language-service": "12.0.5",
"#angular/material": "11.2.13",
"#angular/platform-browser": "12.0.5",
"#angular/platform-browser-dynamic": "12.0.5",
"#angular/router": "12.0.5",
Thanks a lot!
I had to use npm v6 to make a successful update:
npm -g i npm#^6
npm i
ng update #angular/cli#^12 #angular/core#^12
I had got same error on every version angular update when i used official update guide https://update.angular.io/ and command npx #angular/cli#12 update #angular/core#12 #angular/cli#12.
After long googling and trying i found next way for angular and angular material update (example for 10 to 11 update):
npx #angular/cli#11 update #angular/core#11 #angular/cli#11
getting subj error
remove node_modules and package-lock.json
npm install
Git commit
ng update #angular/core#11 --migrate-only --from 10 --to 11
Git commit
ng update #angular/cli#11 --migrate-only --from 10 --to 11
Git commit
npx #angular/cli#11 update #angular/material#11 #angular/flex-layout#11.0.0-beta.33
Downgrad npm v6, I tried bunch of commands after googling get successful now
npm -g i npm#^6
npm i
ng update #angular/cli#^12 #angular/core#^12
I had this same issue which was confusing as a beginner
I initially tried this command, but I just got another error
ng update #angular/cli #angular/core
I then found this link https://github.com/angular/angular-cli/issues/20843 and one person said to do this global cli command, this seemed to have fixed the issue when creating a new project
npm i #angular/cli -g
I can now create my new project command e.g.:
ng new example --routing false --style css --skip-git --skip-tests
Update your tsconfig.json and then run
sudo npm install --force

Error when trying to install react-redux dependency

I am getting an error trying to install the react-redux package onto my create-react-app application. I have tried deleting and reinstalling my node_modules folder as well as installing it with admin permissions and I am still receiving the same error
➜ frontend git:(main) ✗ npm i react-redux
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
Here is the remaining output from the console
npm ERR!
npm ERR! While resolving: frontend#0.1.0
npm ERR! Found: react#17.0.1
npm ERR! node_modules/react
npm ERR! react#"^17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^16.8.3" from react-redux#7.2.1
npm ERR! node_modules/react-redux
npm ERR! react-redux#"*" 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.
Here is the list of current dependencies in my package.json
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.21.0",
"react": "^17.0.1",
"react-bootstrap": "^1.4.0",
"react-dom": "^17.0.1",
"react-router-bootstrap": "^0.25.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.4",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"tachyons": "^4.12.0"
},
It looks like you are using the latest npm version (v7).
As mention in the logs, try with
npm install --legacy-peer-deps
The last time npm Blog mentioned the --legacy-peer-deps flag was while their beta version of npm v7 got public. To read more about the flag go here.
Two ways:
npm install <package-name> --legacy-peer-deps
install Recommended node version for most users
The better way is to install the recommended version of node to work for all packages.
Try installing recommended nodejs version(screen shot below). Which should fix this issue.
Here is a recreation of this error and its solution (screenshots below):
Problem:
Nodejs : Latest features:
Solution:
Nodejs : Recommended for most users:
Installing the Recommended version of node js fixed this issue instantly allowing installation of relevant dependancies.
Incase you are facing this issue with a react-native dependency then once you have installed the recommended version be sure to update your pod file.
Try using Node.js latest "Recommended For Most Users" Version .
it worked for me
I had this issue and nothing seemed to work.
I fixed it by downgrading node to version 12.14.1
Uninstall the current node version and install 12.14.1 from this link
Tried for Mac, it worked.. follow the steps for upgrading to the latest LTS
Before updating the Node.js release, check which version you are currently using with:
node -v
Next, clear npm cache with the command:
npm cache clean -f
Install n globally:
npm install -g n
Now that you have n installed, you can use the module to install the latest stable release of Node.js:
sudo n stable
Alternatively, you can install the Node.js release with the latest features:
sudo n latest
Or, install a specific version number with:
n [version.number]
I faced the same issue, so id run this command
npm config set legacy-peer-deps true
Then I simply created my react app using redux template by following
npx create-react-app app-name --template redux
worked for me!!
Its a little bit late but you can resolve this with --force or --legacy-peer-deps options. Either should work as mentioned in the error reported by npm
Try adding it with yarn. Worked for me

Cant build app using npx grunt on Windows

On Windows 8.1 installed Node.js 12.16.
First I run "npm install grunt" in a root directory of project.
Installation passed succesfully, however with the following warnings:
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion#
1, but npm-shrinkwrap.json was generated for lockfileVersion#0. I'll try to do m
y best with it!
npm WARN deprecated minimatch#0.2.14: Please update to minimatch 3.0.2 or higher
to avoid a RegExp DoS issue
npm WARN deprecated coffee-script#1.3.3: CoffeeScript on NPM has moved to "coffe
escript" (no hyphen)
npm WARN deprecated minimatch#0.3.0: Please update to minimatch 3.0.2 or higher
to avoid a RegExp DoS issue
npm WARN platform-web#0.0.1 No repository field.
npm WARN platform-web#0.0.1 No license field.
npm WARN The package time-grunt is included as both a dev and production depende
ncy.
npm WARN The package object-assign is included as both a dev and production depe
ndency.
+ grunt#0.4.5
added 38 packages from 47 contributors and audited 54 packages in 3.026s
found 25 vulnerabilities (5 low, 6 moderate, 14 high)
run `npm audit fix` to fix them, or `npm audit` for details
Root directory containts grunt-folder (root_dir/grunt), in which Gruntfile.js and package.json files are located.
And this grunt-folder containts other grunt-folder (root_dir/grunt/grunt). This second grunt containts some js-files.
Then in "root_dir/grunt" I run "npx grunt". But the build aborted with the following log:
>> Local Npm module "grunt-contrib-clean" not found. Is it installed?
>> Local Npm module "grunt-contrib-copy" not found. Is it installed?
>> Local Npm module "grunt-includes" not found. Is it installed?
>> Local Npm module "grunt-text-replace" not found. Is it installed?
>> Local Npm module "grunt-contrib-concat" not found. Is it installed?
>> Local Npm module "grunt-contrib-uglify" not found. Is it installed?
>> Local Npm module "grunt-contrib-cssmin" not found. Is it installed?
>> Local Npm module "grunt-file-creator" not found. Is it installed?
>> Local Npm module "grunt-war" not found. Is it installed?
>> Local Npm module "nexus-deployer" not found. Is it installed?
Warning: Task "clean:all" not found. Use --force to continue.
Aborted due to warnings.
package.json is
{
"name": "platform-web",
"version": "0.0.1",
"description": "Platform",
"devDependencies": {
"archiver": "^0.12.0",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-cssmin": "0.12.3",
"grunt-contrib-uglify": "^0.6.0",
"grunt-file-creator": "^0.1.3",
"grunt-includes": "^0.5.1",
"grunt-text-replace": "^0.4.0",
"grunt-war": "^0.5.1",
"nexus-deployer": "^0.1.8",
"object-assign": "^4.0.1",
"time-grunt": "^1.1.0"
},
"dependencies": {
"time-grunt": "^1.0.0",
"object-assign": "^4.0.1"
}
}
What am I doing wrong?
p.s.: root-folder is:
Following is only needed for older versions of grunt. New one install the bunstubbs correctly so you can still install grunt via npm and not globally.
Install grunt-cli. This will correctly pick up whichever version of grunt the project is running and execute it.
npm install grunt-cli --save-dev
In the package.json change dev script to
"scripts": {
"start": "npx grunt-cli"
}
then run
npm run start

What could cause an error related to npm not being able to find a file? No contents in my node_modules subfolder. Why is that?

I'm trying to run npm install in the angular project folder I got from ASP.NET Boilerplate and I'm getting an error that is "related to npm not being able to find a file."
D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular>npm install
npm WARN deprecated #types/moment#2.13.0: This is a stub types definition for Moment (https://github.com/moment/moment). Moment provides its own type definitions, so you don't need #types/moment installed!
npm WARN codelyzer#3.2.2 requires a peer of #angular/compiler#^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer#3.2.2 requires a peer of #angular/core#^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.1.3 (node_modules\fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Error: EPERM: operation not permitted, rename 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\.staging\fsevents-8cc0601e\node_modules\are-we-there-yet' -> 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\.staging\are-we-there-yet-cedb4a6a'
npm ERR! path D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\#angular-devkit\build-optimizer\node_modules\typescript
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\#angular-devkit\build-optimizer\node_modules\typescript' -> 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\#angular-devkit\build-optimizer\node_modules\.typescript.DELETE'
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:\Users\Jack\AppData\Roaming\npm-cache\_logs\2018-03-21T19_33_18_250Z-debug.log
I can clearly see that this is happening because my node_modules subfolder contains only a single folder structure with no files within it. That structure is:
node_modules\#angular-devkit\build-optimizer\node_modules
I have node 8.9.4, npm 5.6.0, and angular-CLI 1.5.0 installed as well as typescript 2.0.0. The latter two packages have been installed globally.
Here are the package.json file contents:
{
"name": "MyProject",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --port 4200",
"hmr": "ng serve --host 0.0.0.0 --port 4200 4201 --hmr -e=hmr",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.0.3",
"#angular/common": "^5.0.3",
"#angular/compiler": "^5.0.3",
"#angular/core": "^5.0.3",
"#angular/forms": "^5.0.3",
"#angular/http": "^5.0.3",
"#angular/platform-browser": "^5.0.3",
"#angular/platform-browser-dynamic": "^5.0.3",
"#angular/router": "^5.0.3",
"#aspnet/signalr": "1.0.0-preview1-28189",
"#types/bootstrap": "^3.3.33",
"#types/jquery": "^3.2.12",
"#types/jquery.blockui": "0.0.28",
"#types/jquery.validation": "^1.16.3",
"#types/lodash": "^4.14.62",
"#types/moment": "^2.13.0",
"#types/moment-timezone": "^0.2.34",
"#types/signalr": "^2.2.33",
"#types/toastr": "^2.1.33",
"abp-ng2-module": "^1.3.0",
"abp-web-resources": "^3.3.0",
"animate.css": "^3.5.2",
"block-ui": "^2.70.1",
"bootstrap": "^3.3.7",
"bootstrap-select": "^1.12.2",
"chart.js": "^2.6.0",
"core-js": "^2.4.1",
"famfamfam-flags": "^1.0.0",
"flot": "^0.8.0-alpha",
"font-awesome": "^4.7.0",
"jquery": "^3.1.1",
"jquery-countto": "^1.2.0",
"jquery-migrate": "^3.0.0",
"jquery-slimscroll": "^1.3.8",
"jquery-sparkline": "^2.4.0",
"js-cookie": "^2.1.4",
"lodash": "^4.17.4",
"moment": "^2.18.1",
"moment-timezone": "^0.5.13",
"morris.js": "^0.5.0",
"ngx-bootstrap": "^2.0.2",
"ngx-pagination": "^3.0.3",
"node-waves": "^0.7.5",
"push.js": "1.0.4",
"raphael": "^2.2.7",
"rxjs": "^5.5.2",
"signalr": "^2.2.1",
"simple-line-icons": "^2.4.1",
"spin.js": "^2.3.2",
"sweetalert": "^2.0.8",
"toastr": "^2.1.2",
"ts-helpers": "^1.1.2",
"web-animations-js": "^2.3.1",
"zone.js": "0.8.18"
},
"devDependencies": {
"#angular/cli": "^1.5.4",
"#angular/compiler-cli": "^5.0.3",
"#angularclass/hmr": "^2.1.3",
"#types/jasmine": "^2.5.38",
"#types/node": "^8.0.27",
"codelyzer": "^3.1.2",
"jasmine-core": "^2.5.2",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^1.4.1",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-coverage-istanbul-reporter": "^1.3.0",
"karma-jasmine": "^1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"nswag": "^11.12.7",
"protractor": "^5.1.1",
"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"typescript": "2.4.2"
}
}
When I run npm install, I can see the packages being downloaded into the .staging folder. At the point that the finalize command is run (see the log below), I can see that the package folders are being consolidated and copied somewhere, but that somewhere does not appear to be my node_modules subfolder other than the first set of subfolders as I have shown above. When the npm install completes, the .staging folder is deleted and all that I have left is that partial folder structure.
Admittedly I am new to Node development - I usually work on our ASP.NET Web API backends. I'm trying to get my development environment in sync with our front-end developer's development environment. I have spent most of the day looking for a solution. I've tried uninstalling and reinstalling Node. I've tried different versions that match our front-end developer's environment. I've tried using the latest versions of angular-CLI and typescript and have fallen back to the versions I reference above in hopes that the "requires a peer" warnings would be resolved. I have searched for similar answers on this site. The closest one I have found remains unanswered.
Here is the end of the "complete log" referenced in the npm error output:
19577 silly saveTree | `-- tsutils#2.22.2
19577 silly saveTree +-- typescript#2.4.2
19577 silly saveTree +-- web-animations-js#2.3.1
19577 silly saveTree `-- zone.js#0.8.18
19578 warn codelyzer#3.2.2 requires a peer of #angular/compiler#^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
19579 warn codelyzer#3.2.2 requires a peer of #angular/core#^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
19580 warn optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.1.3 (node_modules\fsevents):
19581 warn optional SKIPPING OPTIONAL DEPENDENCY: Error: EPERM: operation not permitted, rename 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\.staging\fsevents-8cc0601e\node_modules\are-we-there-yet' -> 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\.staging\are-we-there-yet-cedb4a6a'
19582 verbose optional SKIPPING OPTIONAL DEPENDENCY:
19582 verbose optional Please try running this command again as root/Administrator.
19583 verbose stack Error: ENOENT: no such file or directory, rename 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\#angular-devkit\build-optimizer\node_modules\typescript' -> 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\#angular-devkit\build-optimizer\node_modules\.typescript.DELETE'
19584 verbose cwd D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular
19585 verbose Windows_NT 10.0.16299
19586 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
19587 verbose node v8.9.4
19588 verbose npm v5.6.0
19589 error path D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\#angular-devkit\build-optimizer\node_modules\typescript
19590 error code ENOENT
19591 error errno -4058
19592 error syscall rename
19593 error enoent ENOENT: no such file or directory, rename 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\#angular-devkit\build-optimizer\node_modules\typescript' -> 'D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular\node_modules\#angular-devkit\build-optimizer\node_modules\.typescript.DELETE'
19594 error enoent This is related to npm not being able to find a file.
19595 verbose exit [ -4058, true ]
Please advise.
The following steps work for me:
npm cache clean -f
rm -rf node_modules
npm i
It might be related to corruption in Angular Packages or incompatibility of packages.
Please follow the below steps to solve the issue.
Delete node_modules folder manually.
Install Node ( https://nodejs.org/en/download ).
Install Yarn ( https://yarnpkg.com/en/docs/install ).
Open command prompt , go to path angular folder and run Yarn.
Run angular\nswag\refresh.bat.
Run npm start from the angular folder.
Update
ASP.NET Boilerplate suggests here to use yarn because npm has some problems. It is slow and can not consistently resolve dependencies, yarn solves those problems and it is compatible to npm as well.
I had the SAME issue today and it was driving me nuts!!! What I had done was upgrade to node 8.10 and upgrade my NPM to the latest I uninstalled angular CLI
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
I then verified my Cache from NPM if it wasn't up to date I cleaned it and ran the install again
if npm version is < 5 then use npm cache clean --force
npm install -g #angular/cli#latest
and created a new project file and create a new angular project.
Try the following steps:
1. Make sure you have the latest npm (npm install -g npm).
2. Add an exception to your antivirus to ignore the node_modules folder in your project.
3. $ rm -rf node_modules package-lock.json .
4. $ npm install
Following what #viveknuna suggested, I upgraded to the latest version of node.js and npm using the downloaded installer. I also installed the latest version of yarn using a downloaded installer. Then, as you can see below, I upgraded angular-cli and typescript. Here's what that process looked like:
D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular>npm install -g #angular/cli#latest
C:\Users\Jack\AppData\Roaming\npm\ng -> C:\Users\Jack\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.1.3 (node_modules\#angular\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ #angular/cli#1.7.3
added 75 packages, removed 166 packages, updated 61 packages and moved 24 packages in 29.084s
D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular>npm install -g typescript
C:\Users\Jack\AppData\Roaming\npm\tsserver -> C:\Users\Jack\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
C:\Users\Jack\AppData\Roaming\npm\tsc -> C:\Users\Jack\AppData\Roaming\npm\node_modules\typescript\bin\tsc
+ typescript#2.7.2
updated 1 package in 2.427s
D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular>node -v
v8.10.0
D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular>npm -v
5.6.0
D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular>yarn --version
1.5.1
Thereafter, I ran yarn and npm start in my angular folder and all appears to be well. Here's what that looked like:
D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular>yarn
yarn install v1.5.1
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.1.3: The platform "win32" is incompatible with this module.
info "fsevents#1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "#angular/cli > #schematics/angular#0.1.10" has incorrect peer dependency "#angular-devkit/schematics#0.0.40".
warning "#angular/cli > #angular-devkit/schematics > #schematics/schematics#0.0.10" has incorrect peer dependency "#angular-devkit/schematics#0.0.40".
warning " > codelyzer#3.2.2" has incorrect peer dependency "#angular/compiler#^2.3.1 || >=4.0.0-beta <5.0.0".
warning " > codelyzer#3.2.2" has incorrect peer dependency "#angular/core#^2.3.1 || >=4.0.0-beta <5.0.0".
[4/4] Building fresh packages...
Done in 232.79s.
D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular>npm start
> MyProject#0.0.0 start D:\Dev\AspNetBoilerplate\MyProject\3.5.0\angular
> ng serve --host 0.0.0.0 --port 4200
** NG Live Development Server is listening on 0.0.0.0:4200, open your browser on http://localhost:4200/ **
Date: 2018-03-22T13:17:28.935Z
Hash: 8f226b6fa069b7c201ea
Time: 22494ms
chunk {account.module} account.module.chunk.js () 129 kB [rendered]
chunk {app.module} app.module.chunk.js () 497 kB [rendered]
chunk {common} common.chunk.js (common) 1.46 MB [rendered]
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 515 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 1.1 MB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 1.53 MB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 15.1 MB [initial] [rendered]
webpack: Compiled successfully.
If it happens, then it means you have to upgrade your node.js. Simply uninstall your current node from your pc or mac and download the latest version from https://nodejs.org/en/
In my case
npm cache clean --force
Also not working so, I use
yarn
First, install yarn globally
npm i -g yarn
Then instead of "npm start", I do,
yarn add
This works for me.
I had faced the same problem. After google search I found this solution:
'git' is not recognized as an internal or external command
Check this out hope your problem will be solved
In my case, this error happened with a new project.
none of the proposed solutions here worked, so I simply reinstalled all the packages and started working correctly.
In my case I tried to run npm i firebase#7.8.2 and got the error because the dev server was running in another terminal on vsc. Hit ctrl+c, y to stop it in that terminal, and then installation works.
In my case, I had to create a new app, reinstall my node packages, and copy my src document over. That worked.
Change your firebase.json from:
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
}
To:
{
"functions": {
}
}
I was trying to do it in a folder inside dropbox. I think dropbox was locking files as it uploaded them or something and that didn't work. It would fail in different places.

Resources