繁体   English   中英

无法使用 pkg 从 nodejs 应用程序创建二进制文件

[英]Unable to create a binary from nodejs app using pkg

我无法使用 pkg 命令从 nodejs 应用程序创建二进制可执行文件。

我有一个简单的 nodejs 应用程序,仅包含三个 .js 文件,即: index.jsxlsx_to_pdf.jsxlsx_extractor.js

这就是我的 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"
  }
}

whatsapp-web.js 使用 puppeteer。

当我尝试使用命令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 应用程序编译为可执行文件的替代方法,那将非常有帮助。

我不知道。 从来没有这样做过。 但我认为你应该为编译你的程序的平台设定目标

pkg -o /bin/my-program -t node14-win-x64

https://github.com/vercel/pkg你也可以阅读这个。 https://github.com/vercel/pkg/issues/935

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM