'NestJs: Failed to execute command: npm install --silent

After I installed Nest globally, I tried creating a new project but I got this error Failed to execute command: npm install --silent.

nest new new_project


Solution 1:[1]

Same here. No answer was helpful to me. I got it working by:

nest new test-project
cd test-project
npm install @types/[email protected]
npm install

Solution 2:[2]

Is a problem whit Urix module https://github.com/lydell/urix#deprecated

Try:

npm cache clean --force
npm i -g source-map-resolve
npm i -g @nestjs/cli
nest new project_name

Solution 3:[3]

I encountered this issue on my Linux desktop.

When the error occurs?

The error occurs after the nest CLI created the project skeleton and moved to the dependencies installation with npm / yarn.

Debugging

After running next new <project-name> I accessed the new create folder (project-name) and tried to run npm install from there:

npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 1000:1000 "/home/my-user/.npm"
npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /home/my-user/.npm/_cacache/tmp/ef585472
npm ERR! errno -13

npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 1000:1000 "/home/my-user/.npm"

The cause of the error

The problem in my case was related to permissions to the _cache folder inside the .npm folder of the current user path.

Solution:

I fixed this by simply running:

sudo chown -R 1000:1000 /home/my-user/.npm/_cache

Then running npm install inside the failed project folder.
On new project the problem should not occur.

Additional information:

1 ) Running npm cache clean --force gave me the exact same error which npm install produced.

2 ) Running next new <project-name> with sudo might be a workaround but it is better to solve the permissions issues without running the process with sudo.


Versions I used:

I'm working with:

$nest -v
7.5.3

$node -v
v12.19.0

Solution 4:[4]

I was getting the same error using an older version of Node (v12.7.0) and using Yarn (v1.22.5).

I fixed the problem by using nvm to install the long-term support (LTS) version of Node and then reinstalling the Nest CLI.

nvm install --lts
npm install -g @nestjs/cli

Solution 5:[5]

I got the same error.

Failed to execute command: npm install --silent
× Installation in progress... ?
? Packages installation failed, see above

I have tried all the solution mentioned here nothing worked for me, so I decided to uninstall node and reinstall it.

To uninstall node I refer this https://stackoverflow.com/a/20711410/15543025.

Previously i was using
node version: 16.6.2
npm version: 7.20.6

After uninstalling node I installed LTS version of node(i.e v14.17.5), it includes npm version: 6.14.14.

Don't know what the actual problem was but it is working fine on older versions of npm. This could be a possible workaround.

Solution 6:[6]

If create project with yarn package:

 - 1: Run cmd: npm install -g yarn 
 - 2: Run again: nest new <project> then
   choice yarn

Solution 7:[7]

In my case just reinstalling @nestjs/cli fixed it.

npm install -g @nestjs/cli

Solution 8:[8]

I fix it by install yarn globally.

I just execute this command: npm install -g yarn

After that I execute create new nestjs app and it work:

nest new nestjs-app

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ehrlich_Bachman
Solution 2 Gianmar
Solution 3
Solution 4 Solidus Snake
Solution 5 Jay Godhani
Solution 6 Nguyên Ph?m
Solution 7 Lars Flieger
Solution 8 MiCoder