繁体   English   中英

节点找不到全局安装的npm模块

[英]node cannot find globally installed npm module

node (18.7.0) 找不到全局安装的 npm (8.18.0) 模块。

我的app.js包括:

let jp = require('jsonpath')

命令行和输出:

$ npm install -g jsonpath
…

$ npm -g list
/usr/local/lib
├── @aws-amplify/cli@9.2.1
├── jsonpath@1.1.1
└── npm@8.18.0

$ 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

是的,这行不通! 因为您的app.js将在当前项目node_modules中使用jsonpath ,而不是您全局安装的那个。 您必须在当前项目中安装库,只需运行:

npm install jsonpath

然后它将正常工作!

嗨,是的,正如朋友所说,在您的路径项目中打开终端并输入

npm i jsonpath

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM