无法安装spookyjs

时间:2018-04-09 13:17:51

标签: node.js phantomjs casperjs node-modules spookyjs

我想安装spookyjs并发现无法这样做。我尝试了三种不同的方式:

  1. 运行spookyjs github中提供的标准spookyjs package.json。 然后我尝试运行hello.js,我受到了这个错误的欢迎。

       C:\Users\User1\Desktop\test2>node hello.js
    events.js:183
          throw er; // Unhandled 'error' event
          ^
    
    Error: spawn casperjs ENOENT
        at _errnoException (util.js:1022:11)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
        at onErrorNT (internal/child_process.js:372:16)
        at _combinedTickCallback (internal/process/next_tick.js:138:11)
        at process._tickCallback (internal/process/next_tick.js:180:9)
        at Function.Module.runMain (module.js:695:11)
        at startup (bootstrap_node.js:188:16)
        at bootstrap_node.js:609:3
    
  2. 全局安装了phantomjs和casperjs,package.json安装了spooky和tiny-jsonrpc。我收到相同的错误消息。

  3. package.json

    安装了这些依赖项
    "dependencies": {
        "spooky": "^0.2.5",
        "tiny-jsonrpc": "^2.0.1",
        "phantom": "^4.0.12",
        "casperjs": "^1.1.4"
    
  4. 我得到了同样的错误。

1 个答案:

答案 0 :(得分:0)

我遇到了这个链接: Issue

并详细说明了解决方案。这是一大堆代码:

const
  path = require('path'),
  _ = require('underscore')
;
var
  // close env to pass to spawn
  env = _.clone(process.env),
  // get the PATH - in my local Windows, it was Path
  envPath = env.PATH || env.Path,
  // get path to node_modules folder where casperjs and
  // phantomjs-prebuilt are installed
  // this will be different for you
  binDir = path.join(__dirname, './../../node_modules/.bin'),
  Spooky = require('spooky')
;
// update the path in the cloned env
env.PATH = env.Path = `${envPath};${binDir}`;


var spooky = new Spooky({
  child: {
    // spooky is trying to call casperjs.bat for windows
    // .bat doesn't work, so call the update .cmd file
    // this fixes issue 2 with the file
    command: /^win/.test(process.platform) ? 'casperjs.cmd' : 'casperjs',
    transport: 'http' ,
    spawnOptions: {
      // set the env using cloned version
      // this fixes issue 1 with the path
      env: env
    }
  },
  ... 

所以现在程序运行没有错误。实际上虽然它运行没有任何东西,因为虽然一方面没有弹出错误,另一方面没有弹出任何东西。通过将console.log()置于幽灵般的回调函数中进行重新编写,但没有显示任何内容。那是另一个问题,但是......

但是我收到的错误消失了,解释器运行代码。