node (18.7.0) cannot find globally installed npm (8.18.0) module.
My app.js
includes:
let jp = require('jsonpath')
Command lines & outputs:
$ npm install -g jsonpath
…
$ npm -g list
/usr/local/lib
├── @aws-amplify/[email protected]
├── [email protected]
└── [email protected]
$ node app.js
node:internal/modules/cjs/loader:959
throw err;
^
Error: Cannot find module 'jsonpath'
Require stack:
- /Users/user/Code/project/js/app.js
at Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1022:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/user/Code/project/js/app.js:1:10)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
at Module.load (node:internal/modules/cjs/loader:998:32)
at Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/user/Code/project/js/app.js'
]
}
Node.js v18.7.0
CodePudding user response:
Yes, this won't work! Because your app.js
will use jsonpath
in current project node_modules
, not the one you installed globally. You have to install library in current project, just simply run:
npm install jsonpath
Then it will work properly!
CodePudding user response:
Hi yes As a friend said open terminal in your path project and type
npm i jsonpath