npm install myPackage -g, Error: Cannot find module 'commander' - node.js

I am Chinese, my English is not good.
I submit a npm package,this package dependent on commander, i sure the commander had install.
Then i install my package, when i use it, the console show 'Error: Cannot find module 'commander', i'm confused.
this is code:
"devDependencies": {
"chalk": "^2.4.1",
"commander": "^2.15.1",
"download-git-repo": "^1.0.2",
"handlebars": "^4.0.11",
"inquirer": "^6.0.0",
"log-symbols": "^2.2.0",
"ora": "^2.1.0"
}
when i npm install -g my package,the 'commander' could not be found:
https://i.stack.imgur.com/KpDzt.png

Related

React/React Native dependency issues

I've been working on a react native app, and I keep running into dependency issues. I finally ironed out my dependencies so that I can actually npm install. Now I am trying to add react-native-image-mapper, and while our app is using react 17, react-native-image-mapper wants react 16.8.3. I tried using that react version, but then all the rest of my dependencies were off. I was reading that react 17 was a "gradual" upgrade from 16, so I tried to npm i --force, but then my app would not run at all.
Here are the dependencies from package.json:
"#react-navigation/bottom-tabs": "^6.0.8",
"#react-navigation/native": "^6.0.4",
"#react-navigation/native-stack": "^6.2.2",
"#use-expo/font": "^2.0.0",
"axios": "^0.21.1",
"cloudinary": "^1.27.1",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"expo": "~42.0.1",
"expo-app-loading": "1.1.2",
"expo-camera": "^11.2.2",
"expo-font": "~9.2.1",
"expo-status-bar": "~1.0.4",
"express": "^4.17.1",
"firebase": "8.2.3",
"firebase-admin": "^9.12.0",
"morgan": "^1.9.1",
"pg": "^8.5.1",
"react": "17.0.1",
"react-native": "0.64.2",
"react-native-keyboard-aware-scroll-view": "^0.9.4",
"react-native-safe-area-context": "3.2.0",
"react-native-screens": "^3.4.0",
"react-native-select-dropdown": "^1.2.0",
"react-native-web": "^0.17.5",
"react-redux": "^7.2.4",
"redux": "^4.1.0",
"redux-devtools-extension": "^2.13.9",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"sequelize": "^6.3.5",
"uuid": "^8.3.2"
},
"devDependencies": {
"#babel/core": "^7.12.10",
"#babel/preset-react": "^7.12.10",
"#babel/register": "^7.12.10",
"babel-loader": "^8.2.2",
"eslint": "^7.32.0",
"eslint-plugin-react": "^7.26.1",
"esm": "^3.2.25",
"nodemon": "^1.19.4",
"react-dom": "17.0.1"
}
Here is the error message I get when I try to add react-native-image-mapper:
npm ERR!
npm ERR! While resolving: mole-tracks#0.0.1
npm ERR! Found: react#17.0.1
npm ERR! node_modules/react
npm ERR! react#"17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"16.8.3" from react-native-image-mapper#0.1.11
npm ERR! node_modules/react-native-image-mapper
npm ERR! react-native-image-mapper#"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
Is there any simple way to untangle problematic dependencies? Is there something glaringly wrong with our dependencies as they stand?
I'm looking for practical advice on how to solve this specific problem as well as tips for avoiding this kind of thing in the future.
Try to use this command
npm install --legacy-peer-deps
I looked at the react-native-image-mapper library and I can say that its structure is poor as a library therefore it gives you the error. If you want to use it anyway, I suggest you just copy the source code (which is only 1 page) and add it to your project as a component.
There is no need to install it because there are no native parts that exist in the code. Only JavaScript.

node-pre-gyp ERR! Tried to download(404) while migration in windows 10

May be this question already asked but that's not solving my issue.
I try to migrate my Node.Js project one system to another one system, that time application shows bcrypt error while npm install. Error is following:
package.json:
"dependencies": {
"aws-sdk": "^2.325.0",
"bcrypt": "^2.0.1",
"bluebird": "^3.5.1",
"compression": "^1.0.3",
"cors": "^2.5.2",
"crypto-js": "^3.1.9-1",
"date-and-time": "^0.6.2",
"date-fns": "^1.29.0",
"dateformat": "^3.0.2",
"generate-password": "^1.5.1",
"get-mac-address": "^1.0.0",
}
help me to solve this issue.
You could try
npm --build-from-source install bcrypt
or
npm install --global --production windows-build-tools
before installing the package.json.
Hope this might work.

node app fails to run on mojave: ReferenceError: internalBinding is not defined

I've tried to unsuccessfully run a node app, which runs fine on both High Sierra and Windows 10, but fails on Mojave 10.14.1.
This is the error shown when running the gulp build_dev task:
[23:44:42] Requiring external module babel-register
fs.js:25
'use strict';
^
ReferenceError: internalBinding is not defined
at fs.js:25:1
at req_ (/Users/user1/Documents/NodeProjects/myapp/node_modules/natives/index.js:137:5)
at Object.req [as require] (/Users/user1/Documents/NodeProjects/myapp/node_modules/natives/index.js:54:10)
at Object.<anonymous> (/Users/user1/Documents/NodeProjects/myapp/node_modules/vinyl-fs/node_modules/graceful-fs/fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:707:30)
at Module._extensions..js (internal/modules/cjs/loader.js:718:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/user1/Documents/NodeProjects/myapp/node_modules/babel-register/lib/node.js:152:7)
at Module.load (internal/modules/cjs/loader.js:605:32)
at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
at Function.Module._load (internal/modules/cjs/loader.js:536:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myapp#1.0.0 dev: `node node_modules/gulp/bin/gulp.js build_dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myapp#1.0.0 dev 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/user1/.npm/_logs/2018-11-04T22_44_42_709Z-debug.log
This is the content of the package.json file with all the dependencies used in the application:
{
"name": "myapp",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test-dev": "node node_modules/gulp/bin/gulp.js test_dev",
"test-prod": "node node_modules/gulp/bin/gulp.js test_prod",
"dev": "node node_modules/gulp/bin/gulp.js build_dev",
"prod": "node node_modules/gulp/bin/gulp.js build_prod"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-polyfill": "^6.26.0",
"body-parser": "^1.17.2",
"cookie-parser": "^1.4.3",
"envify": "^4.1.0",
"express": "^4.16.2",
"glob": "^7.1.2",
"http-status-codes": "^1.1.6",
"morgan": "^1.8.2",
"multi-glob": "^1.0.1",
"npm": "^6.4.1",
"path": "^0.12.7"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.26.0",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-preset-env": "^1.6.0",
"babel-register": "^6.24.1",
"babelify": "^7.3.0",
"browser-sync": "^2.26.3",
"browserify": "^16.1.0",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-if": "^2.0.2",
"gulp-imagemin": "^3.3.0",
"gulp-minify-css": "^1.2.4",
"gulp-nodemon": "^2.2.1",
"gulp-notify": "^3.0.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-sass-glob": "^1.0.8",
"gulp-sourcemaps": "^2.6.0",
"gulp-uglify": "^3.0.0",
"gulp-util": "^3.0.8",
"imagemin-pngquant": "^5.0.1",
"run-sequence": "^2.2.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
}
}
Any hint on how to debug this problem? Could be related to gcc compiler version?
node version: 11.1.0
npm version: 6.4.1
At this link I've uploaded the log of the "npm install" command to install dependencies: npm_install.log
Try updating natives to the latest version. This commit seems to resolve the issue you're having.
I downgraded Node version from 10.15.0(LTS) to 10.10.0. And this fixed internalBinding error for me.
sudo npm cache clean -f
sudo npm install -g n
sudo n 10.10.0
In my case, the issue was with the node_modules installation, so do the following.
Perform a yarn audit
Check if you have any critical vulnerabilities
Either upgrade the version of the module or search for an alternative module.
yarn install
You should be good to go
Note: Issue was not with the node version in my case it was just a vulnerable module(gulp-angular-templatecache). I also suggest you do npm upgrade and npm rebuild if the above method doesn't work.
npm audit doesn't work with private repositories but yarn audit does.

NPM in Windows not installing module or adding to package.json

I have no idea why I get an error for mongoskin. I used this module before but I got rid of it. I removed the node_modules directory then did a fresh npm install, fine everything installs. Then I tried to add a new module minimist as seen below:
C:\www\instantynode\src>npm install minimist --save
npm WARN package.json instanty#0.1.1 No description
npm WARN package.json instanty#0.1.1 No repository field.
npm WARN package.json instanty#0.1.1 No README data
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "minimist" "--save"
npm ERR! node v4.4.0
npm ERR! npm v2.14.20
npm ERR! code EPEERINVALID
npm ERR! peerinvalid The package mongodb#2.1.4 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer mongoskin#1.4.13 wants mongodb#~1.4
npm ERR! Please include the following file with any support request:
npm ERR! C:\www\instantynode\src\npm-debug.log
package.json:
{
"name": "app",
"version": "0.1.1",
"description": "",
"dependencies": {
"bunyan": "1.5.1",
"co": "4.6.0",
"cookie-parser": "^1.4.0",
"forever": "^0.15.1",
"fs": "0.0.2",
"geoip-lite": "^1.1.6",
"handlebars": "^4.0.5",
"jsonwebtoken": "^5.4.1",
"jwt-simple": "^0.4.0",
"koa": "^1.1.2",
"koa-better-ratelimit": "^2.1.2",
"koa-bodyparser": "^2.0.1",
"koa-conditional-get": "^1.0.3",
"koa-generic-session": "^1.10.0",
"koa-handlebars": "^0.5.7",
"koa-mount": "^1.3.0",
"koa-multer": "1.0.0",
"koa-passport": "^2.0.1",
"koa-redis": "^1.0.1",
"koa-router": "^5.3.0",
"koa-static": "^1.5.2",
"lodash": "^3.10.1",
"mongodb": "2.1.4",
"nodemailer": "2.1.0",
"nodemon": "^1.8.1",
"passport": "^0.3.2",
"passport-http-bearer": "^1.0.1",
"passport-local": "^1.0.0",
"socket.io": "^1.3.7",
"socketio-jwt": "^4.3.3"
},
"devDependencies": {
"assert": "1.3.0",
"del": "2.1.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "3.1.0",
"gulp-concat": "2.6.0",
"gulp-concat-css": "2.2.0",
"gulp-imagemin": "2.4.0",
"gulp-less": "3.0.5",
"gulp-minify-css": "1.2.2",
"gulp-notify": "2.2.0",
"gulp-uglify": "1.5.1",
"imagemin-pngquant": "4.2.0",
"jsdoc": "3.4.0",
"node-inspector": "0.12.5",
"run-sequence": "1.1.5"
},
"main": "app.js",
"scripts": {
"startfn": "forever start -c \"nodemon --harmony\" app.js --exitcrash",
"startf": "forever start -c \"node --harmony\" app.js",
"start": "node --harmony app.js"
},
"author": "",
"license": "ISC"
}
npm install minimist --save does not work as you can see, does not install or add itself to the package.json file. And it is still mentioning mongoskin?
I have a feeling that the NPM in Windows is buggy?
i think that mongoskin only work with mongodb driver older than 1.4. You might have installed mongoskin in global mode, try to remove it.
You are trying to install minimist, which has its own package.json with its own dependencies. In these it says that it wants mongoskin to be installed, which has a dependency on mongodb itself, but in another version than you have it (you have 2.1.4 but as the error says, it needs ~1.4).
So, because you provided the --save parameter, you want npm to respect these dependencies and do not install mongodb in the desired version on top of it.
Ok I've found the issue. The NPM in Windows is way more sensitive than the one in Linux. In Linux I can manually remove the line from the package.json file and just remove the node_modules directory. However in Windows it appears to be cached by NPM, so I had to manually use the npm remove mongoskin --save command.
When I did this so that the package.json looked like it should I was able to install minimist via npm install minimist --save without issues!
I'm not surprised Windows... Not surprised...
In your package.json, try to change this:
"mongodb": "2.1.4",
to this:
"mongodb": "1.4.*",

npm install dependency order

In my package.json, I have:
"devDependencies": {
"download": "^0.1.18",
"grunt": "^0.4.5",
"grunt-autoprefixer": "^0.8.0",
"grunt-contrib-imagemin": "^0.7.1",
"grunt-contrib-less": "^0.11.3",
"grunt-contrib-requirejs": "^0.4.4",
"grunt-contrib-watch": "^0.6.1"
}
When I run npm install, it tries to install grunt-contrib-imagemin before anything else and it throws an error.
The workaround is to npm install download, THEN npm install grunt-contrib-imagemin manually, then npm install the rest of the packages.
Why doesn't npm install respect the order of the packages listed in devDependencies?

Resources