问题
After updating node.js and npm to current LTS:
node -v
v12.16.0
npm -v
6.13.4
When I'm trying to install @angular-cli following the steps in the documentation, running npm install -g @angular/cli
in the terminal stops the installation and the console output is:
npm install -g @angular/cli
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
/Users/user/.npm-global/bin/ng -> /USERS/USER/.npm-global/lib/node_modules/@angular/cli/bin/ng
> @angular/cli@9.0.2 postinstall /USERS/USER/.npm-global/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js
+ @angular/cli@9.0.2
updated 1 package in 12.202s
And in this case, ng new project-name
yields -bash: ng: command not found
. Any help would be very welcome as I have a big project coming up.
Thanks all.
回答1:
The issue you are experiencing has noting to do with npm warning
you see in console ref. It is seems more likely a problem with permissions on your machine or NodeJS installation issue or both.
I would recommend to remove your NodeJS installation completely at first and then install NVM to manage your NodeJS instances:
- Mac/Linux: https://github.com/nvm-sh/nvm
- Windows:https://github.com/coreybutler/nvm-windows
Once you done installing NVM try to install Angular CLI:
npm install @angular/cli -g
Hope it helps!
UPDATE: Also you can check this issue
回答2:
I removed "node_modules" folder & "package-lock.json" file and then execute following 2 commands:
npm init
npm install
And then, it worked properly.
回答3:
Uninstalling and installing angular cli
works fine for me.
回答4:
$brew install angular-cli
Installed angular9.0.3(stable) This depends on node13.08.0
https://formulae.brew.sh/formula/angular-cli
回答5:
I tried cleaning cache and it worked for me.
npm cache clean --force
回答6:
I faced same issue in my Angular 9 project, I just copy pasted node_modules folder from my old angular project, I worked fine, Please try this way if nothing worked out. but you will get the same issue if you do npm install, pls don't do.
回答7:
As stated in the documentation, using a Windows 10 machine, to install Angular CLI in a machine with NodeJS and npm package manager
node -v
# v12.16.0
npm -v
# 6.13.4
the first time running
npm install -g @angular/cli
got similar message to yours
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
C:\Users\tiago\AppData\Roaming\npm\ng -> C:\Users\tiago\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
> @angular/cli@10.0.0 postinstall C:\Users\tiago\AppData\Roaming\npm\node_modules\@angular\cli
> node ./bin/postinstall/script.js
+ @angular/cli@10.0.0
added 269 packages from 206 contributors in 97.901s
Then, when running a second time, the message matched yours (notice the last line now doesn't say added 269 packages
; instead, updated 1 package
).
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
C:\Users\tiago\AppData\Roaming\npm\ng -> C:\Users\tiago\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
> @angular/cli@10.0.0 postinstall C:\Users\tiago\AppData\Roaming\npm\node_modules\@angular\cli
> node ./bin/postinstall/script.js
+ @angular/cli@10.0.0
updated 1 package in 8.691s
If I then type
ng --version
I didn't get an error like you. Instead, got the following result
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.0.0
Node: 12.16.0
OS: win32 x64
Angular:
...
Ivy Workspace:
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1000.0
@angular-devkit/core 10.0.0
@angular-devkit/schematics 10.0.0
@schematics/angular 10.0.0
@schematics/update 0.1000.0
rxjs 6.5.5
which shows that it actually didn't fail but got Angular CLI installed.
In fact, when I run (with cd to C:/Users/tiago/Desktop/angular)
ng new my-app
The my-app is created
and can be served (with cd to my-app)
ng serve --open
As I can see the following page, this means the installation and setup was successful.
So, as per your case with -bash: ng: command not found
, this may mean NodeJS wasn't installed properly (I would reinstall it). If that doesn't solve, I've seen another solution to that problem before; simply follow the next steps
- Remove Node from your system
- Install NVM
- Install Node via NVM: nvm install stable
- Run
npm install -g @angular/cli
回答8:
npm cache clean --force
npm install -g @angular/cli
npm install mkdirp
npm cache verify
close the terminal and open it again
ng new newApp
it will work for this issue....
Happy Coding
回答9:
In case if you are facing issue in Windows machine.
Just mention cli version along with the command.
npm i @angular/cli@8.1.0
This worked for me.
Further , you might need to set path variable if getting below issue
'ng' is not recognized as an internal or external command, operable program or batch file
回答10:
Unfortunately, Request package was deprecated. and that according to Mikeal Rogers (creator of request) read this link
and for more information, you can read this article
回答11:
The package request is now fully deprecated. So that will probably take a while to change. I think the solution would be for angular cli to release a new version that is not reliant upon request.
来源:https://stackoverflow.com/questions/60235086/angular-cli-install-fails-with-deprecated-request2-88-2-request-has-been-depr