使用Axios 1.x时PKG无法编译Node.js项目求助
Node.js项目使用Axios 1.5.0无法通过PKG打包为exe的问题
我试过各种方法都没用。开发了一个包含API请求的Node.js应用,用Axios管理请求,但没法通过PKG打包成exe文件。把Axios降级到0.27.0版本能成功打包,但我需要用HTTP/s-proxy-agent,而1.x之前的低版本不支持这个工具,所以必须用1.5.0版本。
PKG打包时的警告信息
> Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/index.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/axios.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/utils.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/helpers/bind.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/core/Axios.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/core/mergeConfig.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/defaults/index.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/helpers/formDataToJSON.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/cancel/CanceledError.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/cancel/CancelToken.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/cancel/isCancel.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/env/data.js > Warning Failed to make bytecode node18-x64 for file /snapshot/ValorantCheckerJs/node_modules/axios/lib/helpers/toFormData.js
我的package.json配置(已尝试PKG配置但无效)
"pkg": { "outputPath": "./dist", "targets": [ "win" ], "assets": [ "./node_modules/axios/dist/node/axios.cjs" ] }, "dependencies": { "axios": "^1.5.0", "child_process": "^1.0.2", "colors": "^1.4.0", "http": "^0.0.1-security", "http-cookie-agent": "^5.0.4", "http-proxy-agent": "^7.0.0", "https-proxy-agent": "^7.0.1", "jsonwebtoken": "^9.0.1", "prompt-sync": "^4.2.0", "socket.io": "^4.7.2" },
额外尝试
我还试过换成node-fetch库,但打包后程序一执行到相关代码就直接退出。
内容的提问来源于stack exchange,提问作者Lawyn
相关产品推荐
相关产品推荐

