我有一个节点 js 应用程序,它在端口 8080 上运行一个本地服务器,它提供一个 index.html 文件。我需要将node js应用程序转换为exe,以便一键运行。我一直在尝试使用nexe 模块将节点 js 应用程序转换为 exe ,但创建的 exe 无法运行并崩溃。我不知道我在哪里做错了,或者我应该尝试使用其他模块。请指导我。这是所需的文件和我的尝试。
包.json 文件
{
"name": "node-web-example",
"version": "1.0.0",
"description": "",
"main": "bundle.js",
"scripts": {
"start": "npm run bundle-js | http-server",
"bundle-js": "watchify main.js -o bundle.js",
"build": "nexe -r bundle.js -r index.html -r style.css -o MyApplication-1.exe -t x86-8.0.0"
},
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"uneeq-js": "^2.35.0"
},
"devDependencies": {
"browserify": "^16.5.0",
"nexe": "^4.0.0-beta.18",
"watchify": "^3.11.1"
}
}
对于 exe 构建,我使用了命令npm run build
但失败了
这是从终端运行 exe 时的错误跟踪
var n=V(105),r=V(106),i=V(83);function o(){return a.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(e,t){if(o()<t)throw new RangeError("Invalid typed array length");return a.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=a.prototype:(null===e&&(e=new a(t)),e.length=t),e}function a(e,t,V){if(!(a.TYPED_ARRAY_SUPPORT||this instanceof a))return new a(e,t,V);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return h(this,e)}return c(this,e,t,V)}function c(e,t,V,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,V,n){if(t.byteLength,V<0||t.byteLength<V)throw new RangeError("'offset' is out of bounds");if(t.byteLength<V+(n||0))throw new RangeError("'length' is out of bounds");t=void 0===V&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,V):new Uint8Array(t,V,n);
ReferenceError: window is not defined
at Module.n.__awaiter.V (D:\Uneeq Demo\examples\web\node\bundle.js:192:140642)
at V (D:\Uneeq Demo\examples\web\node\bundle.js:170:158)
at Object.e.exports (D:\Uneeq Demo\examples\web\node\bundle.js:185:23055)
at V (D:\Uneeq Demo\examples\web\node\bundle.js:170:158)
at Object.setPrototypeOf.__proto__ (D:\Uneeq Demo\examples\web\node\bundle.js:170:957)
at Object.__dirname.2 (D:\Uneeq Demo\examples\web\node\bundle.js:170:967)
at o (D:\Uneeq Demo\examples\web\node\bundle.js:1:327)
at D:\Uneeq Demo\examples\web\node\bundle.js:1:378
at Object.__dirname.1.uneeq-js (D:\Uneeq Demo\examples\web\node\bundle.js:2:22)
at o (D:\Uneeq Demo\examples\web\node\bundle.js:1:327)
但是,如果npm start
在终端中使用,那么它从那里运行良好,并且网页可以在 localhost://8080 打开。
这是完整的目录位置
请高度赞赏任何帮助或指导!