简体   繁体   中英

unable to install npm with node.js

I'm trying to install node.js and npm. Although I was successfully able to install node.js version 16.13.0, I'm not able to use npm, despite selecting it as a package that must be installed along with node.js. After the installation, I ran npm --version but I got this error:

Error: Cannot find module 'node-fetch-npm'
Require stack:
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\make-fetch-happen\index.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\index.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\pacote\lib\remote.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\pacote\lib\git.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\pacote\lib\fetcher.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\pacote\lib\index.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\lib\utils\update-notifier.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\lib\cli.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\bin\npm-cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\ap202\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\make-fetch-happen\index.js:6:15)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
Error: Cannot find module 'node-fetch-npm'
Require stack:
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\make-fetch-happen\index.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\index.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\pacote\lib\remote.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\pacote\lib\git.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\pacote\lib\fetcher.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\pacote\lib\index.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\lib\utils\update-notifier.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\lib\cli.js
- C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\bin\npm-cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\myaccount\AppData\Roaming\nvm\v11.0.0\node_modules\npm\node_modules\npm-registry-fetch\node_modules\make-fetch-happen\index.js:6:15)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)

I have looked at multiple questions on StackOverflow and other online resources but nothing talks about the issue I'm facing.

Try installing a lower version of npm or reinstall.

https://github.com/coala/docker-coala-base/issues/182

My problem is because there is a conflict with npm binary in my system while trying to run vue create project.


In my case, I have two npm binaries. One in AppData\Roaming and one in a custom path in F:\Programs\nodejs\ . The latter binary produces the error., but not the AppData one.

My node.exe binary is living in the F:\ drive.

Installing node-fetch-npm (deprecated) and node-fetch via npm i installs the package in AppData\Roaming , but it suppose to be installed in the F:\ drive.

So, I copied both package folders from AppData\Roaming into the F:\ drive one.

Running vue create is now fixed.

Gracefully uninstalled the unused package in the AppData folder by npm uninstall -g node-fetch node-fetch-npm .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM