Error: Cannot find module 'commander'

Error: Cannot find module 'commander'

当我使用 运行 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)

很可能 package.json 中缺少 commander。安装它并通过执行以下操作将其添加到 package.json

npm install commander --save

卸载 sails 并使用 'sudo' 重新安装解决了它。

npm uninstall sails -g

sudo npm install sails -g

在我的例子中,这是因为节点版本错误。我试过节点 8.15.1 并且它有效。

全局安装 commander

sudo npm install commander -g

  • 这将在/usr/lib/node_modules/ 下安装指挥官模块。

当我尝试在 express-generator 的帮助下设置新应用时。 给出 error:Cannot 找到模块 'commander'

Node version:12.16.1
switch node version :10.16.3

切换节点版本后工作正常..

在我这边,在完成 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。 这可能是因为软件包损坏。