help icon indicating copy to clipboard operation
help copied to clipboard

module.js:549 throw err;

Open ShanthanVoruganti opened this issue 8 years ago • 39 comments

Node.js Version - node-v8.11.1-x64 Windows 10

Installed Nodejs above version and I get these errors when tried to check the npm version through command prompt.

C:\Users\shant>node -v v8.11.1

C:\Users\shant>npm -v module.js:549 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3 module.js:549 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3

ShanthanVoruganti avatar May 13 '18 19:05 ShanthanVoruganti

Check your package.json file and name of main. (package.json>main). some time your main file and npm command doesn't match. as a example. your main js file named as index.js but you trying to run > node server. your node command should be > node index screenshot_20180922122650

correct example >
screenshot_20180922123403

tharindu-kalhara avatar Sep 22 '18 07:09 tharindu-kalhara

If you install node.js via an installation package downloaded from nodejs.org and then later run homebrew to update npm, you will get this error. Just reinstall the downloaded package.

vinhphamh avatar Oct 08 '18 23:10 vinhphamh

This normally happen when you try to require non existing module

For example, const EventEmitter = require("event");

this line has a typo. It should be

const EventEmitter = require("events");

rswijesena avatar Oct 10 '18 10:10 rswijesena

Delete and reinstall node : https://nodejs.org/en/download/

maxgfr avatar Oct 15 '18 13:10 maxgfr

Having this issue on a fresh install of Nodejs on Windows 10 RS4.

Steps to reproduce:

  • Install NodeJS 11.1.0 on Windows
  • Check box for Chocolatey
  • Run npm in Powershell

Result:

PS C:\Users\Operations> npm                                                                                             internal/modules/cjs/loader.js:589                                                                                          throw err;                                                                                                              ^                                                                                                                                                                                                                                           Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'                    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)                                             at Function.Module._load (internal/modules/cjs/loader.js:513:25)                                                        at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)                                                      at startup (internal/bootstrap/node.js:308:19)                                                                          at bootstrapNodeJSCore (internal/bootstrap/node.js:878:3)                                                           internal/modules/cjs/loader.js:589                                                                                          throw err;                                                                                                              ^                                                                                                                                                                                                                                           Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'                    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)                                             at Function.Module._load (internal/modules/cjs/loader.js:513:25)                                                        at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)                                                      at startup (internal/bootstrap/node.js:308:19)                                                                          at bootstrapNodeJSCore (internal/bootstrap/node.js:878:3)   

Looks like something in the installer set the path to npm in the node_modules directory rather than in the nodejs directory. Even after removing C:\Program Files\nodejs\node_modules\npm\bin from the Path, the behavior remains the same.

natejgardner avatar Nov 03 '18 04:11 natejgardner

Node.js Version - node-v8.11.1-x64 Windows 10

Installed Nodejs above version and I get these errors when tried to check the npm version through command prompt.

C:\Users\shant>node -v v8.11.1

C:\Users\shant>npm -v module.js:549 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3 module.js:549 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3

If anybody facing the above issue go to environmental variable delete "C:\Program Files\nodejs\node_modules\npm\bin" this path, it will work

chanakyakarnati22 avatar Dec 05 '18 10:12 chanakyakarnati22

I copied what I wanted to run into the main User folder.... and worked like this...

alinnegrut avatar Jan 08 '19 13:01 alinnegrut

Yes I get no commands on the terminal unless I add the path to %UserProfile%/AppData/Roaming/npm before the path to C:\Program Files\nodejs. I need this because all npm packages with CLI get put into User's folder. Then I get this error, persistently. I don't think deleteing node_module folders and cleaning cache is a sustainable fix. So for now, so I can just work, I just copied all the npm folders from C:\Program Files\nodejs\node_modules\npm to C:\Users\UserName\AppData\Roaming\npm\node_modules\npm

it works. both versions of NPM are the same 6.4.1

cataquil avatar Jan 08 '19 15:01 cataquil

Solved changed the path: This: C:\Program Files\nodejs\node_modules\npm\bin;C:\Program Files\nodejs\

To: C:\Program Files\nodejs;C:\Program Files\nodejs\node_modules\npm\bin

kakadlec avatar Feb 08 '19 12:02 kakadlec

I was encountering this issue on Linux. The following command fixed the issue: npm i npm@latest -g

viorage avatar Feb 14 '19 11:02 viorage

This helped me:

  1. delete content of node_modules/
  2. delete package-lock.json
  3. npm install

tista3 avatar Feb 21 '19 10:02 tista3

npm install typescript

This worked for me

fayaz07 avatar Mar 07 '19 08:03 fayaz07

I have the same problem. but I got some help and solved it successfully.

1. delete the entire `node_modules`

2. run `npm cache clean`, if errors occurred, use `npm cache clean --force`

3. run `npm install`

it works for me.

Deleting the node_modules folder and running 'npm install' solved it for me.

richienabuk avatar Jul 10 '19 19:07 richienabuk

Hi, im getting the same error with

module.js:549
    throw err;
    ^

Error: Cannot find module '-r'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at Function.Module._preloadModules (module.js:753:12)
    at preloadModules (bootstrap_node.js:475:38)
    at startup (bootstrap_node.js:188:9)
    at bootstrap_node.js:612:3

I've tried all the methods used above, has anyone got any other ideas?

therealtimhawkins avatar Aug 02 '19 12:08 therealtimhawkins

Node.js Version - node-v8.11.1-x64 Windows 10

Installed Nodejs above version and I get these errors when tried to check the npm version through command prompt.

C:\Users\shant>node -v v8.11.1

C:\Users\shant>npm -v module.js:549 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3 module.js:549 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3

Hello!

I faced this error for days and resolved as follows:

Check your developer dependencies to see if gulp-sass is installed as in this example:

{    "name": "layout",    "version": "1.0.0",    "description": "",    "main": "gulpfile.js",    "scripts": {      "test": "echo " Error: no test specified \ "&& exit 1"    },    "author": "",    "license": "ISC",    "dependencies": {      "bootstrap": "^ 4.3.1",      "jquery": "^ 3.4.1",      "popper.js": "^ 1.15.0"    },    "devDependencies": {      "gulp": "^ 4.0.2",      "gulp-sass": "^ 4.0.2",      "sass": "^ 1.22.9"    } }

If it is not, simply execute: npm install gulp-sass --save-dev

In my case solved the problem.

marcosconha avatar Aug 13 '19 14:08 marcosconha

Try removing /.npm it works

Adarshreddyash avatar Apr 02 '20 19:04 Adarshreddyash

This helped me: 1 npm install 2 npm run start

yewbdar avatar Apr 02 '20 20:04 yewbdar

hola, elimino los directorios AppData/Roaming/npm y AppData/Roaming/npm-cache. laucnh una nueva consola y está bien

saludos

hello, I delete AppData/Roaming/npm and AppData/Roaming/npm-cache directories. laucnh a new console and it is ok

regards

Node.js Version - node-v8.11.1-x64 Windows 10

Installed Nodejs above version and I get these errors when tried to check the npm version through command prompt.

C:\Users\shant>node -v v8.11.1

C:\Users\shant>npm -v module.js:549 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3 module.js:549 throw err; ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:609:3

116434438_734062677381194_4000207972434220592_n

writes enters %appdata%

and delete the folders npm and npm-cache

makubex64 avatar Jul 31 '20 20:07 makubex64

Screenshot (557)

Anyone can you help me for solve this error , Actually I'm follow some steps but not working
1] remove node module directory or remove npm cache 2] again install node.js or update npm package

again show me same error

Vi1234sh12 avatar Feb 13 '21 11:02 Vi1234sh12