Cannot find module 'commander' - npm

When I try and run my mocha tests I get
$ npm t
> digitalAlarmClock#1.0.0 test /home/durrantm/Dropnot/code/js/mochaChai/digitalAlarmClock
> mocha *.test.js
internal/modules/cjs/loader.js:979
throw err;
^
Error: Cannot find module 'commander'
Require stack:
- /usr/lib/nodejs/mocha/bin/_mocha
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15)
at Function.Module._load (internal/modules/cjs/loader.js:859:27)
at Module.require (internal/modules/cjs/loader.js:1036:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/usr/lib/nodejs/mocha/bin/_mocha:10:17)
at Module._compile (internal/modules/cjs/loader.js:1147:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
at Module.load (internal/modules/cjs/loader.js:996:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/usr/lib/nodejs/mocha/bin/_mocha' ]
}
npm ERR! Test failed. See above for more details.
How to fix?

here's how I solve the issue:
run npm list to see if there's any dependency missing, for example, I saw:
[root#d21b188bb7e1 configurable-http-proxy]# npm list
configurable-http-proxy#4.3.2 /srv/configurable-http-proxy
├── UNMET DEPENDENCY commander#~7.2.0
...
install it manually by
npm install --save commander#~7.2.0

This can happen for several different reasons.
In this case it is because mocha isn't installed.
Fix with
npm install --save-dev mocha

Related

Broken Vue CLI installation npm

after trying to update vue cli to its latest version using npm update, now everytime I run vue it throws the following error:
vue create
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'strip-ansi'
Require stack:
- /usr/lib/node_modules/#vue/cli/node_modules/#vue/cli-shared-utils/lib/logger.js
- /usr/lib/node_modules/#vue/cli/node_modules/#vue/cli-shared-utils/index.js
- /usr/lib/node_modules/#vue/cli/bin/vue.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/usr/lib/node_modules/#vue/cli/node_modules/#vue/cli-shared-utils/lib/logger.js:2:19)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/lib/node_modules/#vue/cli/node_modules/#vue/cli-shared-utils/lib/logger.js',
'/usr/lib/node_modules/#vue/cli/node_modules/#vue/cli-shared-utils/index.js',
'/usr/lib/node_modules/#vue/cli/bin/vue.js'
]
}
Node.js v17.3.0
If I try to uninstall the package, I also get an error:
sudo npm uninstall -g #vue/cli
npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /usr/lib/node_modules/#vue/cli
npm ERR! dest /usr/lib/node_modules/#vue/.cli-kgOlUxFE
npm ERR! errno -39
npm ERR! ENOTEMPTY: directory not empty, rename '/usr/lib/node_modules/#vue/cli' -> '/usr/lib/node_modules/#vue/.cli-kgOlUxFE'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-02-17T17_58_23_457Z-debug-0.log
I don't know what to do, I need vue cli working
Thanks in advance
You can try to remove the node_modules folder and install all dependencies again with npm install.

ReferenceError: primordials is not defined - bootstrap 4 install

I'm using below url to start bootstrap 4 with gulp:
https://coursetro.com/posts/design/72/Installing-Bootstrap-4-Tutorial
But I got below Error when i run gulp command.
ReferenceError: primordials is not defined
at fs.js:39:5
at req_ (X:\Users\pradeep.patel\Desktop\PP\Website\PP\node_modules\natives\index.js:143:24)
at Object.req [as require] (X:\Users\pradeep.patel\Desktop\PP\Website\PP\node_modules\natives\index.js:55:10)
at Object. (X:\Users\pradeep.patel\Desktop\PP\Website\PP\node_modules\graceful-fs\fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:1185:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
at Module.load (internal/modules/cjs/loader.js:1034:32)
at Function.Module._load (internal/modules/cjs/loader.js:923:14)
at Module.require (internal/modules/cjs/loader.js:1074:19)
at require (internal/modules/cjs/helpers.js:72:18)
I have run below commands, and issue resolved:
npm install -g minimatch (Enter)
npm install -g graceful-fs (Enter)
npm link gulp (Enter)
Thanks,
PP

Error: Cannot find module '../lib/cli.js'

i installed yarn/webpack and after that npm crashed! I get the following error:
npm -v
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module '../lib/cli.js'
Require stack:
- /usr/local/lib/node_modules/npm/bin/npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:1)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/usr/local/lib/node_modules/npm/bin/npm-cli.js' ]
}
The error appears whatever I like to do with npm. I'm working on Mac OSX 10.14.6
Node Version: 15.4.0
Yarn Version: 1.22.10
thanks for help.
This happened to me when I used brew install node. I fixed it by doing brew uninstall node (just to clean up) and then installing nodejs by downloading the package from https://nodejs.org/
Just uninstall using brew uninstall node, download and install package from https://nodejs.org.

ReferenceError: resolve is not defined (`ExtractTextPlugin.extract`)

Before ask this question I searched the SO, get the bellow related post:
ReferenceError: resolve is not defined
But it is not fit my case, because mine is error on the webpack config, I don;t know why get this issue.
When I use the npm run build, I get the bellow error:
/Users/ldsole/Desktop/my-project/web/wx_backup/webpack.base.config.js:51
use: ExtractTextPlugin.extract({
^
ReferenceError: resolve is not defined
at Object.<anonymous> (/Users/luowensheng/Desktop/my-project/web/wx_backup/webpack.base.config.js:51:40)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/luowensheng/Desktop/my-project/web/wx_backup/webpack.prod.config.js:5:27)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wx_backup#1.0.0 build: `webpack --progress --hide-modules --config webpack.prod.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the wx_backup#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/lasdas/.npm/_logs/2018-04-08T05_51_10_773Z-debug.log
You see the npm ERR! This is probably not a problem with npm. There is likely additional logging output above., I don't know where why get the error.
My cause error code (webpack.base.config.js) is bellow:
{
test: /\.css$/,
use: ExtractTextPlugin.extract({ // there is the error line.
use: ['css-loader?minimize', 'autoprefixer-loader'],
fallback: 'style-loader'
})
},

Cannot find module '_baseIsRegExp'

I am getting this error while running gulp, I already have babel-register installed.
[18:51:21] Requiring external module babel-register
module.js:327
throw err;
^
Error: Cannot find module './_baseIsRegExp'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (D:\ndbsite\src\NdbSite.UI\node_modules\babel-plugin-transform-class-properties\node_modules\babel-helper-function-name\node_modules\babel-types\node_modules\lodash\isRegExp.js:1:82)
at Module._compile (module.js:409:26)
at Module._extensions..js (module.js:416:10)
at Object.require.extensions.(anonymous function) [as .js] (D:\ndbsite\src\NdbSite.UI\node_modules\babel-register\lib\node.js:156:7)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
seems I am missing some package. Not sure how to find it. Please Help.
The issue I was facing because of old packages referenced inside other Modules were not updated
As suggested by #loganfsmyth in comment. I updated node & npm. Still issue exists since old packages were not updated inside the hierarchy.
Resolution is to delete old folders using rimraf and then npm install with new node & npm :
npm install rimraf -g
rimraf node_modules
npm install