NodeJS:Error: Cannot find module 'jshint'


NodeJS的一个问题,提示如下:


 Error: Cannot find module 'jshint'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (F:\nodejs\ionic_wp\hooks\before_prepare\01_jshint.js:5:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
Error: Hook failed with error code 1: F:\nodejs\ionic_wp\hooks\before_prepare\01_jshint.js
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:194:23
    at _rejected (C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:797:24)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:823:30
    at Promise.when (C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:1035:31)
    at Promise.promise.promiseDispatch (C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:741:41)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:557:44
    at flush (C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:108:17)
    at process._tickCallback (node.js:355:11)

其实我很奇怪的额,因为jshint是全局可用的:
test.js的内容


 // 目标文件test.js的内容
/* jshint unused: true */
var a = 1;
var b = 2;
alert(b);

使用jshint测试输出:


 λ jshint test.js
test.js: line 3, col 5, 'a' is defined but never used.

1 error

环境为:
Windows 7 + NodeJS + Gulp,环境变量NODE_PATH已设置。

在生成应用时,一个劲儿的提示找不到jshint模块,不知为何,哪位师兄给看看为何?

gulp node.js jshint

ERO☆MAX 10 years, 4 months ago

原因找到了,很简单,也很低级,我重装了下NodeJS,PATH不对,已修正。

八云移动中心 answered 10 years, 4 months ago

额,题看错了,以为你用 gulp-jshint 的。

也可以在node中引入 gulp jshint


 npm install gulp-jshint --save

引入后,在 gulpfile 中加入 task ,就可以跑了~

土豆头太大 answered 10 years, 4 months ago

全局可用不代表本地可用啊


 npm install jshint

会跑的雪糕 answered 10 years, 4 months ago

Your Answer