簡體   English   中英

pkg 打包后節點串行端口不起作用

[英]Node serialport doesn't work after packaging by pkg

我正在開發一個通過串行端口與信用卡讀卡器通信的 node.js 應用程序。 我使用“節點串行端口”,它工作得很好。

但是通過 pkg 打包后,控制台顯示如下錯誤信息並且 serialport 不起作用。


(node:14044) UnhandledPromiseRejectionWarning: Error: Could not locate the bindings file. Tried: → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\build\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\build\\Debug\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\build\\Release\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\out\\Debug\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\Debug\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\out\\Release\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\Release\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\build\\default\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\compiled\\10.17.0\\win32\\x64\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\addon-build\\release\\install-root\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\addon-build\\debug\\install-root\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\addon-build\\default\\install-root\\bindings.node → D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\lib\\binding\\node-v64-win32-x64\\bindings.node at bindings (D:\\snapshot\\app_ver3.0.0\\node_modules\\bindings\\bindings.js:126:9) at Object.<anonymous> (D:\\snapshot\\app_ver3.0.0\\node_modules\\@serialport\\bindings\\lib\\win32.js:1:98) at Module._compile (pkg/prelude/bootstrap.js:1261:22) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:651:32) at tryModuleLoad (internal/modules/cjs/loader.js:591:12) at Function.Module._load (internal/modules/cjs/loader.js:583:3) at Module.require (internal/modules/cjs/loader.js:690:17) at Module.require (pkg/prelude/bootstrap.js:1166:31) at require (internal/modules/cjs/helpers.js:25:18) (node:14044) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:14044) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


當然,我的 D 驅動器中沒有“快照”目錄。 (我認為它是一種Node串行端口的默認目錄)

我完全不知道。 有沒有人可以解決這個問題? :(

(再次抱歉我的英語不好)

我在我的一個項目中遇到了同樣的問題。 我認為問題在於 pkg “不知道”如何處理 .node 文件。 因此,在打包期間,這些文件會被留下。 我通過將@serialport 文件夾(及其全部內容)與包文件放在一起解決了這個問題。 雖然它奏效了,但我仍然很好奇如何將它們打包在一起。 我正在四處尋找,發現了你的問題。

我希望有更好的解決方案出現..

包.json

 "pkg": {
    "assets": [
      "node_modules/@serialport/**"
    ],
    "scripts": [
      "node_modules/@serialport/**"
    ]
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM