Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 [email protected]
3 info using [email protected]
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.


1 Answers

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)?

like image 119
iLuvLogix Avatar answered Sep 05 '25 04:09

iLuvLogix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!