我在debian 6上安装了nodejs 0.10.15。然后使用npm我安装了:
sudo npm install grunt-cli -g
我还在我的本地测试目录中执行了npm install(将必要的依赖项下载到node_modules目录),其中包含以下package.json文件:
{
"name": "sample-name",
"version": "1.4.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-qunit": ">0.0.0",
"grunt-qunit-istanbul": ">0.0.0"
}
}
这是安装phantomjs时的输出:
...
Writing location.js file
Done. Phantomjs binary available at /home/myuser/Test/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs
Done. Phantomjs binary available at /home/myuser/Test/node_modules/grunt-qunit-istanbul/node_modules/grunt-lib-phantomjs-istanbul/node_modules/phantomjs/lib/phantom/bin/phantomjs
grunt@0.4.1 node_modules/grunt
├── which@1.0.5
...
但是当我从测试目录中运行 grunt test 时,我得到了:
Running PhantomJS...ERROR
>> In order for this task to work properly, PhantomJS must be installed locally
>> via NPM. If you're seeing this message, generally that means the NPM install
>> has failed. Please submit an issue providing as much detail as possible at:
>> https://github.com/gruntjs/grunt-lib-phantomjs/issues
Warning: PhantomJS not found. Use --force to continue.
如果我运行在前一个指定位置安装的phantomjs脚本没有任何反应,我会得到退出代码127(表示问题路径:http://tldp.org/LDP/abs/html/exitcodes.html)。如果我捕捉到phantomjs bash脚本,它看起来像这样:
#!/usr/bin/env node
var path = require('path')
var spawn = require('child_process').spawn
var binPath = require(path.join(__dirname, '..', 'lib', 'phantomjs')).path
var args = process.argv.slice(2)
// For Node 0.6 compatibility, pipe the streams manually, instead of using
// `{ stdio: 'inherit' }`.
var cp = spawn(binPath, args)
cp.stdout.pipe(process.stdout)
cp.stderr.pipe(process.stderr)
cp.on('exit', process.exit)
process.on('SIGTERM', function() {
cp.kill('SIGTERM')
process.exit(1)
})
据我所知,这意味着phantomjs在节点内执行。如果我开始节点输入路径var我得到:
:~$ env node
> var path = require('path')
undefined
>
(我理解的是默认行为:node.js displays "undefined" on the console)
有关进一步调试此问题的建议吗?
答案 0 :(得分:27)
尝试运行
npm uninstall phantomjs
然后运行
npm install phantomjs -g
这应该确保使用命令行安装幻像,以便grunt可以使用它,并且还应该确保它干净地安装。
答案 1 :(得分:3)
尝试
npm install grunt-mocha -D
答案 2 :(得分:2)
尝试在终端中运行以下内容:
npm install phantomjs-prebuilt@2.1.14 --ignore-scripts