简体   繁体   中英

npm cannot find module 'encoding'

So I encounter this kind of problem in npm. I'm using VSCode, btw my laptop is newly formated my OS is Ubuntu. The error that I came across when I install something is:

npm ERR! code MODULE_NOT_FOUND
npm ERR! cannot find module 'encoding'

    // Log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'install', '-g', 'jshint' ]
2 info using npm@5.8.0
3 info using node@v8.11.2
4 verbose npm-session 94ee8611aa9e8514
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for jshint@latest Cannot find module 'encoding'
8 verbose stack Error: Cannot find module 'encoding'
8 verbose stack     at Function.Module._resolveFilename (module.js:547:15)
8 verbose stack     at Function.Module._load (module.js:474:25)
8 verbose stack     at Module.require (module.js:596:17)
8 verbose stack     at require (internal/module.js:11:18)
8 verbose stack     at Object.<anonymous> (/usr/share/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/body.js:13:17)
8 verbose stack     at Module._compile (module.js:652:30)
8 verbose stack     at Object.Module._extensions..js (module.js:663:10)
8 verbose stack     at Module.load (module.js:565:32)
8 verbose stack     at tryModuleLoad (module.js:505:12)
8 verbose stack     at Function.Module._load (module.js:497:3)
8 verbose stack     at Module.require (module.js:596:17)
8 verbose stack     at require (internal/module.js:11:18)
8 verbose stack     at Object.<anonymous> (/usr/share/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/index.js:15:14)
8 verbose stack     at Module._compile (module.js:652:30)
8 verbose stack     at Object.Module._extensions..js (module.js:663:10)
8 verbose stack     at Module.load (module.js:565:32)
9 verbose cwd /opt/lampp/htdocs/My Website #1
10 verbose Linux 4.18.0-parrot8-amd64
11 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "jshint"
12 verbose node v8.11.2
13 verbose npm  v5.8.0
14 error code MODULE_NOT_FOUND
15 error Cannot find module 'encoding'
16 verbose exit [ 1, true ]

I tried reinstalling Node.js/npm but still not working.

When reading through your verbose output you can read in line 7:

silly fetchPackageMetaData error for jshint@latest Cannot find module 'encoding'

You obviously tried to install jshint globally via npm () as stated here:

verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "jshint"

This could be dependency issues with your node and your npm version..

Or conflicts in node_modules folder. Good idea to make sure it's clean, try:

rm -rf node_modules && npm install

Also check your NODE_PATH in case npm tries installing it into a location that's not your NODE_PATH..

EDIT:

I just tried on debian with node v8.11.1 and npm 6.0.1 and it worked fine for me..

Have you tried it with these or other versions of node and npm (using LTS)?

If I understood your question you have some problem to install npm in your system.

try with these 2 steps

1.) run command npm cache clean

2.) then remove the npm folder from the file structure and re-install npm

Possible dependency missing,

try:

rm -rf node_modules && npm install

if you are mac, linux user and you are having privileges issues

try:

rm -rf node_modules && npm install

I just encountered this issue for the first time, and what happened in my case was I kept my Node.js dev server running for the application, but I actually moved the location of the app into a new folder while the server was running. A simple restart of the server from the new location fixed it.

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