简体   繁体   English

电子:找不到模块“电子预建”

[英]Electron: Cannot find module 'electron-prebuilt'

I have an Electron app that uses Nightmare.js when one of the buttons is clicked. 当单击其中一个按钮时,我有一个使用Nightmare.js的Electron应用程序。 It works fine before being packaged, but after I compile it to an .exe file with electron-packager, it will work as intended, until I click the button that makes use of Nightmare.js. 在打包之前,它可以正常工作,但是在使用电子打包程序将其编译为.exe文件之后,它将按预期工作,直到我单击使用Nightmare.js的按钮。 I get this error: 我收到此错误:

Uncaught Error: Cannot find module 'electron-prebuilt'
    at Module._resolveFilename (module.js:470)
    at Function.Module._resolveFilename (C:\app-directory\app-name-win32-ia32\resources\electron.asar\common\reset-search-paths.js:35)
    at Function.Module._load (module.js:418)
    at Module.require (module.js:498)
    at require (internal/module.js:20)
    at Object.<anonymous> (C:\app-directory\app-name-win32-ia32\resources\app\node_modules\nightmare\lib\nightmare.js:16)
    at Object.<anonymous> (C:\app-directory\app-name-win32-ia32\resources\app\node_modules\nightmare\lib\nightmare.js:528)
    at Module._compile (module.js:571)
    at Object.Module._extensions..js (module.js:580)
    at Module.load (module.js:488)

Make sure electron-prebuilt had been added into development dependency in your package.json . 确保在package.json中将electron-prebuilt已添加到development dependency中。 You can install module by npm install --save-dev electron-prebuilt 您可以通过npm install --save-dev electron-prebuilt安装模块

The correct way to require the app module in Electron is: 在Electron中要求app模块的正确方法是:

const {app} = require('electron')

Hope it help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM