【发布时间】:2013-08-15 14:28:11
【问题描述】:
我已经在 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(表示问题 PATH:http://tldp.org/LDP/abs/html/exitcodes.html)。如果我 cat 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 在节点内部执行。如果我启动节点输入我得到的路径变量:
:~$ env node
> var path = require('path')
undefined
>
(我理解为默认行为:node.js displays "undefined" on the console)
有什么建议可以进一步调试这个问题?
【问题讨论】:
-
你的项目文件夹层次结构是什么? phantomjs 在这个层次结构中的什么位置?
-
测试位于此处:/home/myuser/Test/ 并且 phantomjs 位于上述目的地(运行 npm install 的输出)