npm install error (npm ERR! code EPERM npm ERR! syscall mkdir npm ERR! path D:\node.js\odejs)

Today I just want to learn TS and need the typeScript plug-in, but I reported an error when I installed it with the command npm i typescript -g. It took me 1 hour to solve this problem. Here I will provide you with some solutions

1. All errors install

2. Detailed error explanation

 This error occurs after the modified npmglobal installation path, npm install 包 -gornpm install 包 when it is executed, but it can be executed successfully when running cmd as an administrator (it is inconvenient not to use the administrator mode all the time) .

My reason should be that some paths are wrong because of the use of cnpm

2.1 Modify npm global installation

Note: There are two folders (node_global, node_cache) in your nodejs installation directory. To execute these two commands, you need to open cmd in administrator mode and run these two commands.

1. Command line

npm config set prefix "D:\NodeJS\node_global"

npm config set cache "D:\NodeJS\node_cache"

2. Add node_globalthe path of the above folder to the environment variable

2.2 Repair method

1. You can delete the .npmc file under the C disk user. Although this solution does not change the global installation path, but the essential problem is not solved, it will still be installed on the C disk

2. Run the command line as an administrator every time (not convenient enough, the command line under vscode is not run as an administrator by default)

3. Then modify the permissions of node_global

     1. Right-click the node_global folder, click Properties, then click Security, then click Edit, and check all the permissions.

 test

npm i -g  typescript

result

 end

Hope you guys can solve this problem!!!

Guess you like

Origin blog.csdn.net/weixin_56661658/article/details/128512027