【问题标题】:Cannot find module 'browser-window' with nightmare and nodejs找不到带有噩梦和nodejs的模块“浏览器窗口”
【发布时间】:2015-12-26 18:22:14
【问题描述】:

我很难从 nodejs 运行噩梦。我从自述文件中提供的示例开始,尝试了不同版本的电子预构建和不同的调整,但我总是得到找不到浏览器窗口模块的节点。 这是我的测试:

> node --version
v5.3.0
>
> cat .\package.json
{
  "name": "webautomation",
  "version": "1.0.0",
  "private": true,
  "description": "testing nightmare.js",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "nightmare": "^2.1.2",
    "vo": "^1.0.3"
  },
  "author": "ECH",

  "license": "ISC"
}
>
> npm install
>
> npm ls electron-prebuilt
webautomation@1.0.0 D:\MyEnv\WebAutomation
└─┬ nightmare@2.1.2

  └── electron-prebuilt@0.35.4
>
> cat .\main.js
var Nightmare = require('nightmare');
console.log("require done");
dream = Nightmare();

dream.goto('http://yahoo.com');
dream.end();
>
> node main.js
creation done
module.js:338
    throw err;
    ^


Error: Cannot find module 'browser-window'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous>    (D:\MyEnv\WebAutomation\node_modules\nightmare\lib\runner.js:6:21)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
>

谁能告诉我这里缺少什么?

【问题讨论】:

  • 您可能缺少browser-window 模块?尝试执行npm install --save-dev browser-window,然后再次运行main.js
  • 据我了解浏览器窗口是一个电子模块,应该由电子预建提供。实际上 npm show browser-window 返回 404。

标签: node.js nightmare


【解决方案1】:

我的应用遇到了类似的问题,我认为是因为 API 发生了变化。无论如何,我所做的修复它是这样的:

在 main.js 文件中,我替换了旧行

var BrowserWindow = require('browser-window');

有了这个

var BrowserWindow = require('electron').BrowserWindow;

然后它起作用了。 你可以参考这里的线程:https://github.com/Polymer/polymer-cli/issues/404

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多