错误:找不到模块“commander”

14
当我运行`sails -v`、`sails lift`甚至安装npm时,我遇到了这个错误,请帮忙处理。
Error: Cannot find module 'commander'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/sails/bin/_commander.js:6:15)
    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)
6个回答

14

很可能 commanderpackage.json 中缺失。 可以通过以下方式安装并在 package.json 中添加它:

npm install commander --save

5

全局安装 commander 模块。

sudo npm install commander -g

  • 这将在 /usr/lib/node_modules/ 下安装 commander 模块。

4

卸载 sails,并使用 'sudo' 重新安装解决了此问题。

npm uninstall sails -g

sudo npm install sails -g

4
这对我没有起作用。 - Soren

1
当我尝试使用express-generator设置新应用程序时,出现错误:找不到模块“commander”。
Node version:12.16.1
switch node version :10.16.3

切换节点版本后,工作正常。


0

在我的情况下,这是因为我使用了错误的 Node 版本。我尝试了 Node 8.15.1,它可以正常工作。


0
在我的电脑上,在执行了npm install之后,尝试运行npm run watch时,我遇到了同样的问题:Error: Cannot find module 'commander'。我进行了以下操作:
// delete node_modules (can do manually) or command below
// rm -rf node_modules
npm install

我又可以运行npm run watch了。这可能是因为包文件损坏了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接