Reputation: 3208
I am using the node pkg
package to package up my node app and create a native executable. But for some reason when I use the serialport
npm package in my app, it compiles but when I try to run it it throws this error (no matter what platform I build for):
$ ./app
pkg/prelude/bootstrap.js:1876
throw error;
^
Error: No native build was found for platform=linux arch=x64 runtime=node abi=83 uv=1 libc=glibc node=14.19.2
loaded from: /snapshot/pkg/node_modules/@serialport/bindings-cpp
at Function.path (/snapshot/pkg/node_modules/node-gyp-build/index.js:60:9)
at load (/snapshot/pkg/node_modules/node-gyp-build/index.js:22:30)
at Object.<anonymous> (/snapshot/pkg/node_modules/@serialport/bindings-cpp/dist/load-bindings.js:10:46)
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)
at Module.require (pkg/prelude/bootstrap.js:1855:31)
at require (internal/modules/cjs/helpers.js:101:18)
Here is my package.json
{
"name": "pkg",
"version": "1.0.0",
"dependencies": {
"serialport": "^10.4.0"
}
}
And here is my app.js
const { SerialPort } = require('serialport')
const port = new SerialPort({
path: '/dev/ttyUSB0',
baudRate: 19200,
})
console.log('Serial port opened successfully!')
And this is how I build:
$ pkg app.js --target=node14-linux-x64
> [email protected]
Upvotes: 0
Views: 2953
Reputation: 41
i also had this issue, add in the package.json
the config for PKG and the important part here is the assets
where you have to add the bindings from serialport
, the rest you can configure them for your use.
EDIT: With the config in the package.json i run the build with pkg . --compress Brotli
"pkg": {
"scripts": "build/**/*.js",
"assets": [
"node_modules/@serialport/binding*/**/*"
],
"targets": [
"node18-macos-x64",
"node18-win-x64"
],
"outputPath": "dist"
}
Upvotes: 4