Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After $npm install, Getting Error: Cannot find module '../lib/utils/unsupported.js'

I just came back to work on a React project after working in the Rails environment and found that I cannot run any NPM commands in my Mac terminal. I've tried all the remedies that I have come across but none have worked. The bigger issue is what caused this and how can I avoid it again.

Here is the error. What do I need to do? Please help.

$npm install              internal/modules/cjs/loader.js:550     throw err;     ^  Error: Cannot find module '../lib/utils/unsupported.js'     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)     at Function.Module._load (internal/modules/cjs/loader.js:475:25)     at Module.require (internal/modules/cjs/loader.js:598:17)     at require (internal/modules/cjs/helpers.js:11:18)     at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21     at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:92:3)     at Module._compile (internal/modules/cjs/loader.js:654:30)     at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)     at Module.load (internal/modules/cjs/loader.js:566:32)     at tryModuleLoad (internal/modules/cjs/loader.js:506:12) 

I have tried the following:

$brew update $brew uninstall node $brew install node 

After which the following commands come up as so when $which npm was unknown command before:

$which npm /usr/local/bin/npm  $which node /usr/local/bin/node 

I even tried running:

/usr/local/bin/npm -v 

but get the same error as above while

/usr/local/bin/node -v v9.11.1 

works fine.

added the following to my .zshrc file:

export PATH=/usr/local/bin/node:$PATH export PATH=/usr/local/bin/npm:$PATH 

I have also tried:

$brew uninstall --force node $brew link --overwrite node  Warning: Already linked: /usr/local/Cellar/node/9.11.1 To relink: brew unlink node && brew link node  $rm -rf /usr/local/lib/node_modules/npm     

then,

$node install 

but that does not work, either.

$echo $NODE_PATH 

does come up empty, so I may need to added the following to my .bashrc.

export PATH="/usr/local/bin/npm:/usr/local/bin/node:/usr/local/bin:$PATH"  

That does not work either.

like image 568
bigmugcup Avatar asked Apr 06 '18 03:04

bigmugcup


2 Answers

  1. Uninstall node brew uninstall --force node
  2. Remove the /usr/local/lib/node_modules folder
  3. Install it again brew install node
like image 133
Lucas Lopes Avatar answered Oct 05 '22 22:10

Lucas Lopes


Assume this happens on MacOS, below solution works for me.

  1. brew uninstall --force node
  2. Visit https://nodejs.org/en/ and download the LTS version and install, the error was gone
like image 23
Popeye Avatar answered Oct 05 '22 23:10

Popeye