Node.js:找不到模块“ chai”

aaa:

我正在尝试遵循https://mochajs.org/中的第一个示例

做完了

$ npm install -g mocha

得到

C:\Windows\system32>npm install -g mocha
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install th
e latest version of pug instead of jade
npm WARN deprecated [email protected]: graceful-fs version 3 and before will fai
l on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possibl
e.
C:\Users\TestUser\AppData\Roaming\npm\_mocha -> C:\Users\TestUser\AppData\Roamin
g\npm\node_modules\mocha\bin\_mocha
C:\Users\TestUser\AppData\Roaming\npm\mocha -> C:\Users\TestUser\AppData\Roaming
\npm\node_modules\mocha\bin\mocha
[email protected] C:\Users\TestUser\AppData\Roaming\npm\node_modules\mocha
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected])

还装柴(对不起,我本来忘了提)

C:\Windows\system32>npm install -g chai
[email protected] C:\Users\TestUser\AppData\Roaming\npm\node_modules\chai
├── [email protected]
├── [email protected]
└── [email protected] ([email protected])

这是代码

var assert = require('chai').assert;
describe('Array', function() {
  describe('#indexOf()', function () {
    it('should return -1 when the value is not present', function () {
      assert.equal(-1, [1,2,3].indexOf(5));
      assert.equal(-1, [1,2,3].indexOf(0));
    });
  });
});

不断得到

Error: Cannot find module 'chai'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (c:\git\develop\SendText\test\test2.js:1:76)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)

我究竟做错了什么?

Blackus:

您已chai 全局安装(带-g选件),这就是为什么require找不到它的原因

您需要在本地(在node_modules目录上)安装它,以便require可以找到它。

为此,请键入:

npm install --save-dev chai

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章