错误的 NPM 包版本,Mocha 未知选项 --exit

Wrong NPM Package Version, Mocha Unknown Option --exit

我正在尝试 运行 以下命令,但出现以下错误。

$ mocha --exit
error: unknown option `--exit'

当我 运行 得到以下内容时。

$ mocha --version
2.5.3

所以这让我觉得我的版本是错误的。但是当我试图列出它时,我得到了这个。

$ npm list mocha
MyApp@0.0.0 .../Code
└── mocha@4.0.1 

这让我觉得它是 运行最新版本。

最后一件奇怪的事情是运行宁以下。

$ mocha -h

    ...
    --no-exit                               require a clean shutdown of the event loop: mocha will not call process.exit
    ...
    --use_strict                            enforce strict mode
    --watch-extensions <ext>,...            additional extensions to monitor with --watch
    --delay                                 wait for async suite definition

如您所见,有 --no-exit 选项但没有 --exit 选项。奇怪的是,在查看我的版本中没有出现的 code there is an option for --exit. Also in the code there are 3 more options at the end 时。

知道这里发生了什么以及如何解决它吗?

原来这是因为我全局安装了 Mocha。我 运行 npm ls -g --depth=0 获取我所有的全局包,但没有显示 Mocha。

原来我在全局安装了 Mocha 在我开始使用 NVM 之前

为了解决这个问题,我必须禁用 NVM,从我的旧节点设置中删除 Mocha,然后重新启用 NVM,然后重新启动我的终端。这解决了问题。