无法安装spookyjs

Impossible to install 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"
    

我得到同样的错误。

我遇到了这个 link: 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() 放入 spooky 的回调函数中进行调试,但没有显示任何内容。这是另一个问题...

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