我正在尝试使用react&electronic建立一个桌面应用程序。我可以使用npm start build
来构建项目,但是当我运行可执行文件时,会得到一个带有白色屏幕的节点应用程序,因为该应用程序找不到所需的资源。
这些错误是:
Failed to load resource: net::ERR_FILE_NOT_FOUND /F:/static/css/main.056419ee.chunk.css:1
Failed to load resource: net::ERR_FILE_NOT_FOUND 2.eba76f4b.chunk.js:1
Failed to load resource: net::ERR_FILE_NOT_FOUND main.175818bb.chunk.js:1
F:
是正确的驱动器,但是我不认为Electron应该在驱动器根目录下寻找static
目录。我不知道是什么原因造成的,也不知道为什么会有领先的/
。另外,我不知道为什么要在不同的目录中查找其他两个块文件。这三个文件都位于./build/static/js/
中。
npx create-react-app creative-ontology-editor
npm start
和npm run electron-dev
运行它时,react部分工作正常。从那里,我尝试使用this tutorial和this package example等使电子工作。index.html
这是内置电子应用程序显示的html :(注意:我作了美化,但将缩小的js放在一行中,以便可以轻松看到其余部分)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link rel="shortcut icon" href="/favicon.ico"/>
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/>
<meta name="theme-color" content="#000000"/>
<link rel="manifest" href="/manifest.json"/>
<title>Creative Ontology Editor</title>
<link href="/static/css/main.056419ee.chunk.css" rel="stylesheet">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script>
<script src="/static/js/2.eba76f4b.chunk.js"></script>
<script src="/static/js/main.175818bb.chunk.js"></script>
</body>
</html>
package.json
这是我项目的package.json
。我知道我的开发人员和正常依赖者可能混在一起了,但是我怀疑这是问题的一部分/
{
"name": "creative-ontology-editor",
"version": "0.1.0",
"author": "Joe Bush",
"description": "An applied ontology organization tool",
"private": true,
"main": "public/electron.js",
"dependencies": {
"concurrently": "^4.1.0",
"cross-env": "^5.2.0",
"electron-is-dev": "^1.0.1",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-scripts": "2.1.8",
"typescript": "^3.4.1",
"wait-on": "^3.2.0"
},
"scripts": {
"react-build": "react-scripts build",
"react-test": "react-scripts test",
"react-eject": "react-scripts eject",
"react-start": "react-scripts start",
"electron-build": "electron-builder",
"release": "yarn react-build && electron-builder --publish=always",
"build": "yarn react-build && yarn electron-build",
"electron-dev": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && electron .\"",
"dist": "build"
},
"build": {
"appId": "creative-ontology-editor",
"files": [
"build/**/*",
"node_modules/**/*"
],
"directories": {
"buildResources": "public"
},
"linux": {
"target": [
"AppImage",
"deb"
]
},
"win": {
"target": "NSIS",
"icon": "build/icon.ico"
}
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"electron": "^4.1.3",
"electron-builder": "^20.39.0"
}
}
creative-ontology-editor
|-- build
| |-- static
| | |-- csss
| | +-- js
| | |-- 2.eba76f4b.chunk.js
| | |-- 2.eba76f4b.chunk.js.map
| | |-- main.175818bb.chunk.js
| | |-- main.175818bb.chunk.js.map
| | |-- runtime~main.a8a9905a.js
| | |-- runtime~main.a8a9905a.js.map
| |
| |-- asset-manifest.json
| |-- electron.js
| |-- index.html
| |-- manifest.json
| |-- precache-manifest.825 ... .js
| +-- service-worker.js
|
|-- dist
| |-- win-unpacked
| |-- builder-effective-config.yaml
| |-- creative-ontology-editor Setup 0.1.0.exe
| |-- creative-ontology-editor Setup 0.1.0.exe.blockmap
|
|-- node_modules
|-- public
| |-- electron.js
| |-- index.html
| +-- manifest.json
|
|-- src
| |-- Components
| |-- App.css
| |-- App.js
| +-- index.js
|
+-- package.json
./build/asset-manifest.json
{
"main.css": "/static/css/main.056419ee.chunk.css",
"main.js": "/static/js/main.175818bb.chunk.js",
"main.js.map": "/static/js/main.175818bb.chunk.js.map",
"runtime~main.js": "/static/js/runtime~main.a8a9905a.js",
"runtime~main.js.map": "/static/js/runtime~main.a8a9905a.js.map",
"static/js/2.eba76f4b.chunk.js": "/static/js/2.eba76f4b.chunk.js",
"static/js/2.eba76f4b.chunk.js.map": "/static/js/2.eba76f4b.chunk.js.map",
"index.html": "/index.html",
"precache-manifest.82521987a6df63b594987c0f56a4cbb9.js": "/precache-manifest.82521987a6df63b594987c0f56a4cbb9.js",
"service-worker.js": "/service-worker.js",
"static/css/main.056419ee.chunk.css.map": "/static/css/main.056419ee.chunk.css.map"
}
./build/manifest.json
{
"short_name": "COE",
"name": "Creative Ontology Editor",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
答案 0 :(得分:0)
在Kitze's article中,我的package.json
中缺少一行:
"homepage": "./"
他甚至解释了它:
最后一件事:
在package.json中设置“主页”,否则打包的应用程序将找不到.js和.css文件。