[英]Electron-packager missing module 'electron-prebuilt'
I made a computer app using HTML, CSS and JS but when I try to convert that app to exe file using electron-packager it shows me error 我使用HTML,CSS和JS制作了一个计算机应用程序,但是当我尝试使用电子打包程序将该应用程序转换为exe文件时,显示错误
Cannot find module 'electron-prebuilt' from 'C://myapp/helloworld/'
无法从“ C:// myapp / helloworld /”找到模块“电子预构建”
I am using windows. 我正在使用Windows。
This is the code 这是代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Title</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/style.css" />
<script type="text/javascript" src="js/scripts.js"></script>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script>
</script>
<!--[if IE 9]>
<link rel="stylesheet" type="text/css" media="screen" href="css/style_ie9.css" />
<![endif]-->
</head>
<body>
<h1 class="heading">Hello World!</h1>
</body>
</html>
const {app, BrowserWindow} = require("electron");
const path = require('path')
const url = require('url')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
function createWindow () {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600})
// and load the index.html of the app.
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
// Open the DevTools.
win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
{
"name": "Hello World!",
"version": "0.1.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron .",
"package": "asar pack MyApp.app/Contents/Resources/app MyApp.app/Contents/Resources/app.asar",
"build": "electron-packager . MyApp --ignore=node_modules/electron-* && cp Icon.icns MyApp.app/Contents/Resources/atom.icns"
},
"author": "Kyle Robinson Young <kyle@dontkry.com> (http://dontkry.com)",
"license": "MIT",
"devDependencies": {
"asar": "^0.6.1",
"electron-packager": "^3.2.0",
"electron-prebuilt": "^0.25.2"
}
}
npm install --save electron-packager
Or if you're using a two package.json structure, you could try 或者,如果您使用两个package.json结构,则可以尝试
npm install --save electron-packager
in both /app and higher directory. 在/ app和更高目录中。
Also, does this error occur when you run the npm run pack
command? 另外,在运行
npm run pack
命令时是否会发生此错误?
From the npm documentation: 从npm文档中:
As of version 1.3.1, this package is published to npm under two names: electron and electron-prebuilt.
从1.3.1版开始,此软件包以两个名称发布到npm:电子和电子预建。 You can currently use either name, but electron is recommended, as the electron-prebuilt name is deprecated, and will only be published until the end of 2016.
您目前可以使用任何一个名称,但建议使用电子,因为不赞成使用电子预制名称,并且该名称只会在2016年底之前发布。
Download and install the latest build of Electron for your OS and add it to your project's package.json as a devDependency: 下载并安装适用于您的OS的最新版本的Electron,并将其作为devDependency添加到项目的package.json中:
npm install electron --save-dev
This is the preferred way to use Electron, as it doesn't require users to install Electron globally.
这是使用Electron的首选方式,因为它不需要用户全局安装Electron。
You can also use the -g flag (global) to symlink it into your PATH:
您还可以使用-g标志(全局)将其符号链接到PATH中:
npm install -g electron
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.