NPM Cannot find module 'balanced-match' - node.js

Any command I'm try to run with npm I get:
module.js:340
throw err;
^
Error: Cannot find module 'balanced-match'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/glob/node_modules/minimatch/ node_modules/brace-expansion/index.js:2:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Including when I try to npm install -g balanced-match

I know this is very old, and I hope that you found your answer, but for future questors:
I saw this issue recently when I tried to use npm after upgrading node to a newer version with n.
If you recently moved to a newer version of node, and you experience the error mentioned above, you may fix it by installing the latest version of npm. As this may not be possible, because npm is used to update itself, and npm is obviously not working:
Downgrade back to an earlier version of node where your copy of npm worked.
Update npm: sudo npm install npm#latest -g
Upgrade back to the version of node you were using before.
If that doesn't work, or you think it will be easier anyway, you may have to reinstall npm from binary.
If you haven't changed versions of node recently, you may need to reinstall node, or at least npm, from their websites.

I can suggest you the following link which suggest how to install
npm balanced-match
https://www.npmjs.com/package/balanced-match
or download from
github.com/juliangruber/balanced-match

Related

Always same Type Error occuring when using npm

I always receive the same error when using npm, e.g. npm init
/usr/local/lib/node_modules/npm/lib/utils/unsupported.js:3
var supported = require('../../package.json').engines.node
^
TypeError: Cannot read property 'node' of undefined
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/unsupported.js:3:54)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25: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:155:3)
I tried reinstalling, but it didn't solve the problem.
Can someone help me please?
It looks like you are running recent npm code with an old package.json for your npm installation. That's odd. (Maybe you started doing an npm upgrade and canceled it halfway through?)
If I'm right about this, running this code from your command line should return an old npm version number:
node -p 'require("/usr/local/lib/node_modules/npm/package.json").version'
Then get your version of node with node -v. Odds are good that there is
If you're npm is less than version 6 or your node is less than version 12, you will probably want to uninstall Node.js and npm, and then reinstalling Node.js (which will reinstall npm).
If your version of npm is not before version 6, then your npm executable is somehow reading a version of the package.json that isn't that version. Check for symlink shenanigans by running:
node -p 'require("/usr/local/lib/node_modules/npm/lib/utils/../../package.json`).version"
If that doesn't return the same version as the first command above, you'll probably want to uninstall Node.js and npm, remove all of /usr/local/lib/node_modules/npm if the uninstall didn't remove it, and then reinstall Node.js.

NPM dead after update - cannot find module (OSX)

Just did a minor npm update to the latest version (I can't remember what it was as npm no longer works - hence the question) but I think my installed version before the update was 5.6.0. That could be wrong though.
Anyway after running...
sudo npm install -g npm
... npm no longer works at all. Anything I do results in :
internal/modules/cjs/loader.js:596
throw err;
^
Error: Cannot find module './auth.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-registry-fetch/index.js:7:17)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
Any suggestions?
After trying a few different things including reinstalling node via brew the only thing that worked was to download and run the node installer binary from the node site.
Hope it helps somebody else.
I fixed this issue this way:
yarn global add npm

After node reinstalled: "Cannot find module 'internal/util/types' "

So I had removed node from my computer (mostly, I thought) a couple months ago, and today I reinstalled it. Node's working okay, but when I try to test npm I get this message:
$ npm
module.js:549
throw err;
^
Error: Cannot find module 'internal/util/types'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at evalmachine.<anonymous>:31:26
at Object.<anonymous> (C:\Users\LG\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\fs.js:11:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
I tried using "npm rebuild" as I've seen suggested, but that has no impact on anything. I'm using Node v8.11.2 on Windows (hell if I know what version of NPM). Any clues?
In windows,
Step 1: Go to \global_modules\node_modules,
(C:\Users\youruser\AppData\Roaming\npm )
(C:\Users\youruser\AppData\Roaming\npm-cache)
Step 2: Delete the "npm" folder and all its contents,
Step 3: Go to https://nodejs.org,
Step 4: Download the "Recommended For Most Users" version),
Step 5: Install it
For me this worked.
delete package-lock.json
npm i graceful-fs
npm i vinyl-fs
From your terminal, run
rm -rf ./node_modules
npm update
npm install npm#latest -g
or
sudo npm install npm#latest -g
These should help fix your problem.
Had this same problem. Solved it by going to %AppData% and deleting npm and npm-cache folders.

npm Error “ Cannot find module 'npmlog' ”

I am running CentOS 6 and after logging in, I encounter the following error
module.js:340
throw err;
^
Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /home/dspace/.nvm/v0.10.31/bin/npm:19:11
at Object.<anonymous> (/home/dspace/.nvm/v0.10.31/bin/npm:87:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `npm config delete prefix` or `nvm use --delete-prefix v0.10.31 --silent` to unset it.
I've discovered that it is a version bug and can be resolved either by upgrading the npm version or by deleting the node modules like so;
rm -rf node_modules
Then reinstalling them;
npm install
After removing the modules, npm install failed to run because of missing dependancies i.e. the modules. Now the command shows no response at all.
My node version is v0.10.48
This worked for me
Install nvm:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
Restart the terminal
Run
nvm install node
 
I had the same problem after proposed npm upgrade via npm -i -g npm. But Fedora npm/node installed via dnf has modules links to /usr/lib/node_modules/npm/node_modules.bundled/ from /usr/lib/node_modules/npm/node_modules/. I saw links were broken because usr/lib/node_modules/npm/node_modules.bundled/ disappeared. So reinstallation node,nodejs,npm via dnf/rpm solved the problem.

Error: Cannot find module 'readable-stream'

I was using npm few days ago and all worked fine, but I'm suddenly getting an error when trying to do any npm command.
module.js:487
throw err;
^
Error: Cannot find module 'readable-stream'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npmlog/node_modules/are-we-there-yet/tracker-stream.js:3:14)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
I can't do any npm command, even npm -v show this error, node version is 8.0.0
I'm using latest version of macOS
One of the problems is that I didn't install node using homebrow so uninstalling and installing it again is the last solution for me.
Any help with this?
When on a Mac, use nvm to install node, and switch node versions.
Also can nicely reinstall packages when upgrading versions. nvm install 6 --reinstall-packages-from=5
This is better than homebrew, which I would not suggest for Node on a Mac.

Resources