pkg
pkg copied to clipboard
Error: No native build was found for platform
What version of pkg are you using?
5.7.0
What version of Node.js are you using?
14.19.3
What operating system are you using?
Ubuntu 20.04
What CPU architecture are you using?
x86_64
What Node versions, OSs and CPU architectures are you building for?
node14-linux-x64
Describe the Bug
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]
same issue
any solution?
any solution?
@patsonkaushik yes, there is a solution. You need to copy the prebuilt binaries directory to your project root.
any solution?
@patsonkaushik yes, there is a solution. You need to copy the prebuilt binaries directory to your project root.
=>pkg index.js --target linuxstatic
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)
@martinszeltins but,not working binaries file example (sqlite3,serialport library) raspberry pi
any solution?
@patsonkaushik yes, there is a solution. You need to copy the prebuilt binaries directory to your project root.
Indeed!
TL;DR Copy the folder node_modules/@serialport/bindings-cpp/prebuilds to the location of your binary.
So, I was having the same issue and couldn't find the reason. But by looking at the stack trace:
Error: No native build was found for platform=linux arch=x64 runtime=node abi=93 uv=1 libc=glibc node=16.15.0
loaded from: /snapshot/avr-bulk-flasher/node_modules/@serialport/bindings-cpp
at Function.path (/snapshot/MY_PROJECT/node_modules/node-gyp-build/index.js:61:9)
at load (/snapshot/MY_PROJECT/node_modules/node-gyp-build/index.js:22:30)
at Object.<anonymous> (/snapshot/MY_PROJECT/node_modules/@serialport/bindings-cpp/dist/load-bindings.js:10:46)
at Module._compile (pkg/prelude/bootstrap.js:1930:22)
I opened the file referenced here:
at Function.path (/snapshot/MY_PROJECT/node_modules/node-gyp-build/index.js:61:9)
which looks like this: (simplified)
load.path = function (dir) {
dir = path.resolve(dir || '.')
var nearby = resolve(path.dirname(process.execPath))
if (nearby) return nearby
throw new Error('No native build was found for ' + target + '\n loaded from: ' + dir + '\n')
function resolve (dir) {
// Find matching "prebuilds/<platform>-<arch>" directory
var tuples = readdirSync(path.join(dir, 'prebuilds')).map(parseTuple)
var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0]
if (!tuple) return
// Find most specific flavor first
var prebuilds = path.join(dir, 'prebuilds', tuple.name)
var parsed = readdirSync(prebuilds).map(parseTags)
var candidates = parsed.filter(matchTags(runtime, abi))
var winner = candidates.sort(compareTags(runtime))[0]
if (winner) return path.join(prebuilds, winner.file)
}
}
There you can see the pattern where it looks for the native prebuilds. Complete source of node-gyp-build
any solution?
@patsonkaushik yes, there is a solution. You need to copy the prebuilt binaries directory to your project root.
It doesn't work. Is there any other solution?
I encountered the same problem after the compilation was successful.
Error: No native build was found for platform=win32 arch=x64 runtime=node abi=83 uv=1 libc=glibc node=14.20.0
loaded from: ...\projects\node_modules\usb
at Function.path (...\project\node_modules\node-gyp-build\index.js:60:9)
at load (...\project\node_modules\node-gyp-build\index.js:22:30)
at Object.<anonymous> (...\project\node_modules\usb\dist\usb\bindings.js:8:36)
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)
package.json
{
"name": "project",
"version": "1.0.0",
"bin": "index.js",
"main": "index.js",
"scripts": {
"dev": "cross-env NODE_ENV=preview node index.js",
"build": "pkg -C GZip ."
},
"pkg": {
"outputPath": ".dist",
"targets": [
"node14-win-x64",
"node14-macos-x64",
"node14-linux-x64"
],
"assets": [
"utils/*",
"public/*",
"public/**/*"
]
},
"dependencies": {
"body-parser": "^1.20.0",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"get-pixels": "^3.3.3",
"http-proxy-middleware": "^2.0.6",
"iconv-lite": "^0.6.3",
"node-localstorage": "^2.2.1",
"node-machine-id": "^1.1.12",
"qr-image": "^3.2.0",
"usb": "^2.4.3"
},
"devDependencies": {
"cross-env": "^7.0.3"
}
}
any solution?
@patsonkaushik yes, there is a solution. You need to copy the prebuilt binaries directory to your project root.
prebuild issue solved. however, below error occurs
TypeError: Cannot read properties of undefined (reading 'int64')
at Object.
I added the corresponding module to the "assets" to solve this problem.
package.json
{
...
"pkg": {
"outputPath": ".dist",
"targets": [
"node14-win-x64",
"node14-macos-x64",
"node14-linux-x64"
],
"assets": [
"utils/*",
"public/*",
"public/**/*",
"node_modules/usb/*",
"node_modules/usb/**/*"
]
},
...
}
I added the corresponding module to the "assets" to solve this problem.
I added node_modules/@serialport/bindings-cpp/prebuilds to the assets then problem solved.
package.json
{
...
"pkg": {
"outputPath": ".dist",
"targets": [
...
],
"assets": [
...,
"node_modules/@serialport/bindings-cpp/prebuilds"
]
},
...
}
any solution?
@patsonkaushik yes, there is a solution. You need to copy the prebuilt binaries directory to your project root.
Sorry, what exactly do you mean binary directories?
project/ project/dist project/node_modules/usb
And the files in node_modules/usb/prebuilds android-arm android-arm64 darwin-x64+arm64 linux-arm linux-arm64 linux-ia32 linux-x64 win32-ia32 win32-x64
Tried all the solutions above. My error: Error: No native build was found for platform=darwin arch=arm64 runtime=node abi=93 uv=1 armv=8 libc=glibc node=16.16.0 loaded from: /snapshot/src/printserver/node_modules/usb
at Function.path (/snapshot/src/printserver/node_modules/node-gyp-build/index.js:60:9)
any solution?
@patsonkaushik yes, there is a solution. You need to copy the prebuilt binaries directory to your project root.
Sorry, what exactly do you mean binary directories?
project/ project/dist project/node_modules/usb
And the files in node_modules/usb/prebuilds android-arm android-arm64 darwin-x64+arm64 linux-arm linux-arm64 linux-ia32 linux-x64 win32-ia32 win32-x64
Tried all the solutions above. My error: Error: No native build was found for platform=darwin arch=arm64 runtime=node abi=93 uv=1 armv=8 libc=glibc node=16.16.0 loaded from: /snapshot/src/printserver/node_modules/usb
at Function.path (/snapshot/src/printserver/node_modules/node-gyp-build/index.js:60:9)
Hello,did you solve this problem?I got the same Error,it's happen when i import serialport module in my main.js
This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label
This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.
Anyone with the solution do you mind describing the solution in more detail?
Here's my solution. I'm using ffi-napi and ref-napi, which contain native modules. Firstly I use esbuild to build my project, while marking these two module as external
esbuild --platform=node --bundle packages/server/src/index.ts --outfile=dist/index.js --external:@tigerconnect/ref-napi --external:@tigerconnect/ffi-napi
Then include these two module into assets
{
"bin": "dist/index.js",
"pkg": {
"assets": [
"node_modules/@tigerconnect/ffi-napi/**/*",
"node_modules/@tigerconnect/ref-napi/**/*"
]
},
}
Could someone explain my why this happens with that package? I am facing this issue without pkg and I would really understand what it is going on
Could someone explain my why this happens with that package? I am facing this issue without pkg and I would really understand what it is going on
Those packages contains prebuilt binaries and will be loaded dynamicly, which is hard for pack tools to keep them working. Actually I'm not sure if keeping binaries could help, but I choose to treat them as external packages and keep the directory structures (as assets instead of scripts)
Thank you very much @neko-para ! So it is like those packages are built already for my machine and they are not pure JS so the bundlers like Webpack get confused somehow, would that be? Then the solution would be to tell Webpack ok, ignore those guys and then move those binaries/built files directly into the webpack output built folder. Would that be correct? I have been really struggling with this error using Electron :( that is why I am keen on understanding well the details !
@javierguzman Did you manage it with Webpack? I would be grateful for any info.
I am facing the same problem: Cannot read properties of undefined (reading 'int64').
I use Webpack + Vue + ElectronBuilder.
For anyone that is interested in this project, I created my own forks of both pkg and pkg-fetch:
If someone is interested in helping me create a PR or move your active PR to those repositories.
Thanks 🙏🏼
@stenya I think I did but I do not remember much of it and I am not in the same company I was back then so no access to repo
@javierguzman Did you manage it with Webpack? I would be grateful for any info. I am facing the same problem:
Cannot read properties of undefined (reading 'int64').I use Webpack + Vue + ElectronBuilder.
If you just want any ffi work with webpack, you can take a look at koffi, at least this package provides official examples for using with electron-forge/webpack.
@javierguzman Did you manage it with Webpack? I would be grateful for any info. I am facing the same problem:
Cannot read properties of undefined (reading 'int64').I use Webpack + Vue + ElectronBuilder.
If anyone is interested, here is the solution for ElectronBuilder which works for me: https://github.com/node-ffi-napi/node-ffi-napi/issues/245