节点.js:找不到模块“柴”
Node.js: Cannot find module 'chai'
我正在尝试遵循 https://mochajs.org/的第一个示例
做到了
$ npm install -g mocha
有
C:'Windows'system32>npm install -g mocha
npm WARN deprecated jade@0.26.3: Jade has been renamed to pug, please install th
e latest version of pug instead of jade
npm WARN deprecated graceful-fs@2.0.3: 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
mocha@2.4.5 C:'Users'TestUser'AppData'Roaming'npm'node_modules'mocha
├── escape-string-regexp@1.0.2
├── growl@1.8.1
├── commander@2.3.0
├── diff@1.4.0
├── supports-color@1.2.0
├── debug@2.2.0 (ms@0.7.1)
├── mkdirp@0.5.1 (minimist@0.0.8)
├── jade@0.26.3 (commander@0.6.1, mkdirp@0.3.0)
└── glob@3.2.3 (inherits@2.0.1, graceful-fs@2.0.3, minimatch@0.2.14)
还安装了chai(对不起,我本来忘了提了)
C:'Windows'system32>npm install -g chai
chai@3.5.0 C:'Users'TestUser'AppData'Roaming'npm'node_modules'chai
├── assertion-error@1.0.1
├── type-detect@1.0.0
└── deep-eql@0.1.3 (type-detect@0.1.1)
这是代码
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)
我做错了什么?
您已经全局安装了chai
(使用-g
选项),这就是require
找不到它的原因。
您需要在本地(在您的node_modules
目录中)安装它,以便require
可以找到它。
为此,请键入:
npm install --save-dev chai
您需要
在本地安装chai
才能需要它。
npm install chai
你应该安装 chai
$ npm install --save chai
$ npm install chai
chai@3.5.0 ../../../../../../node_modules/chai
├── assertion-error@1.0.2
├── type-detect@1.0.0
└── deep-eql@0.1.3 (type-detect@0.1.1)
-MacBook-Air:test $ mocha
Array
#indexOf()
✓ should return -1 when the value is not present
1 passing (9ms)
您需要确保两个安装位于同一文件夹中因为如果node_modules文件夹(在摩卡安装期间创建)不在安装 CHI 的同一文件夹中,然后出现错误:找不到模块"柴"。
npm 安装 --全球摩卡
npm install chi
npm 测试(测试已成功执行)
npm install types/chai
安装在本地驱动器中
相关文章:
- 找不到模块捆绑包
- Babel编译错误:找不到模块核心js/library/fn/get迭代器
- 因果报应-找不到模块:错误:无法解析模块'scs'
- module.js在运行iron节点时找不到模块
- 错误:找不到模块'/lib/cli'
- nodeJS中的uglify js“;找不到模块“”;
- 找不到模块'它'当用摩卡/柴测试时
- grunt serve:dist时找不到Angular.js模块,但grunt serve工作正常
- 获取错误模块“;反应”;找不到
- 余烬引擎未捕获错误:找不到模块余烬视图/views/select
- 使用状态语法后找不到模块
- 找不到以前导入的 JS 模块
- 节点.js:找不到模块“柴”
- 错误:使用摩卡测试时找不到模块
- nodemon找不到模块'/路径/to/project/home/index.js'
- 接收'错误:找不到模块'使用browserfy、gullow、react.js
- Sails.js+Grunt"找不到模块“”;错误
- 找不到模块“;睡眠”;,跳跃动作
- Titanium iOS提供can'找不到控制器的模块
- Webpack 缺少模块“找不到模块”