我无法使用pkg命令从nodejs应用程序创建二进制可执行文件。
我有一个简单的nodejs应用程序,仅包含三个. js文件,即:x一个一个一个一个一个一个一个一个一个一个一个和x一个一个一个一个二个一个。
这是我的package.json的外观=〉
{
"name": "whatsapp-order",
"version": "1.0.0",
"description": "This package automates the process of sending orders to whatsapp contacts",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"pdfkit": "^0.13.0",
"pdfkit-table": "^0.1.99",
"qrcode-terminal": "^0.12.0",
"whatsapp-web.js": "^1.18.4",
"xlsx": "^0.18.5"
}
}
whatsap-web.js使用了 puppet 戏。
当我尝试使用命令npx pkg index.js
编译代码时,我收到以下警告。
> pkg@5.8.0
> Targets not specified. Assuming:
node14-linux-x64, node14-macos-x64, node14-win-x64
> Warning Cannot include directory %1 into executable.
The directory must be distributed with executable as %2.
The directory must be distributed with executable as %2.
%1: node_modules\puppeteer\.local-chromium
%2: path-to-executable/puppeteer
> Warning Failed to make bytecode node14-x64 for file /snapshot/whatsapp-order/node_modules/brotli/build/encode.js
> Warning Failed to make bytecode node14-x64 for file /snapshot/whatsapp-order/node_modules/brotli/build/encode.js
> Warning Failed to make bytecode node14-x64 for file C:\snapshot\whatsapp-order\node_modules\brotli\build\encode.js
当我尝试使用命令.\index-win.exe
在cmd中运行生成的可执行文件时,收到以下错误:
pkg/prelude/bootstrap.js:1876
throw error;
^
Error: Cannot find module 'C:\snapshot\whatsapp-order\node_modules\es-get-iterator\node.js'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.
at createEsmNotFoundErr (internal/modules/cjs/loader.js:929:15)
at finalizeEsmResolution (internal/modules/cjs/loader.js:922:15)
at resolveExports (internal/modules/cjs/loader.js:450:14)
at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at Module.require (pkg/prelude/bootstrap.js:1855:31)
at require (internal/modules/cjs/helpers.js:101:18)
at Object.<anonymous> (C:\snapshot\whatsapp-order\node_modules\deep-equal\index.js:14:19)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',
path: 'C:\\snapshot\\whatsapp-order\\node_modules\\es-get-iterator\\package.json',
pkg: true
}
我对此相当陌生,如果你能告诉我问题出在哪里以及如何修复它,或者建议我一种替代方法来编译nodejs应用程序到可执行文件,这将是非常有帮助的。
1条答案
按热度按时间laik7k3q1#
我不确定。从来没有这样做过。但是我认为你应该为你的程序在什么平台编译设定目标
你也可以读这个。