我的Mac上有一个与npm start electron .
配合使用的电子应用。然而,当我使用电子打包器为Mac编译它时,我在打开编译的应用程序文件时出现以下错误
bootstrap.min.css Failed to load resource: net::ERR_FILE_NOT_FOUND
module.js:487 Uncaught Error: Cannot find module './node_modules/jquery/dist/jquery.min.js'
at Module._resolveFilename (module.js:485:15)...
module.js:487 Uncaught Error: Cannot find module 'node-wifi'
at Module._resolveFilename (module.js:485:15)
我认为它与设置正确的文件路径有关,但我在我的index.js和functions.js文件中尝试过以下操作,但它没有工作:
var path = require('path');
module.paths.push(path.resolve('node_modules'));
module.paths.push(path.resolve('../node_modules'));
以下是其他相关文件和命令:
的package.json:
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron ."
},
"devDependencies": {
"electron": "^1.8.4",
"electron-packager": "^12.0.0"
},
"dependencies": {
"electron-packager": "^12.0.0",
"bootstrap": "^4.0.0",
"electron-reload": "^1.2.2",
"electron-store": "^1.3.0",
"jquery": "^3.3.1",
"node-wifi": "^2.0.4",
"sweetalert2": "^7.18.0"
}
构建命令:
electron-packager . --overwrite --platform=darwin --arch=x64 --prune=true --out=release-builds
的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<script>window.$ = window.jQuery = require('jquery');</script>
<script src="functions.js"></script>
<script type='text/javascript'>
// On click we should send event to close window.
</script>
</head>
index.js(依赖关系)
const {app, BrowserWindow , ipcMain, dialog} = require('electron')
const path = require('path');
const url = require('url');
functions.js(依赖项)
const { ipcRenderer } = require("electron");
var child_process = require('child_process');
var wifi = require('node-wifi');
var swal = require('sweetalert2');
const Store = require('electron-store');
const store = new Store();
答案 0 :(得分:0)
它不喜欢构建命令中的--prune=true
。我把它设置为假,它似乎正在工作。