Error: No native build was found for platform

See original GitHub issue

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
> pkg@5.7.0

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:12

github_iconTop GitHub Comments

5reactions
DrSkunkcommented, Jul 4, 2022

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

3reactions
ssk7833commented, Aug 16, 2022

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"
    ]
  },
  ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error running in VSCode: No native build was found ... - GitHub
0 installed via conda (thus, no nvm ). This was my initial error: Error: No native build was found for platform=linux arch=x64 runtime=node...
Read more >
Uncaught Error: No native build was found for platform=win32 ...
I use npm install /path/to/addon to install the addon. Then electron-rebuild and electron-build , which don't complain. But when I run npm start ......
Read more >
Hi, can someone help me with this error please, I am unable to ...
Error : No native build was found for platform=win32 arch=x64 runtime=node abi=108 uv=1 libc=glibc node=18.4.0 loaded from…
Read more >
Error: No native build was found for platform=win32 arch=x64 ...
Error : No native build was found for platform=win32 arch=x64 runtime=node abi=108 uv=1 libc=glibc node=18.7.0
Read more >
Kibana Development 7.15 Yarn Bootstrap Fails no native build ...
[vscode] Error: No native build was found for platform=linux arch=x64 runtime=node abi=83 uv=1 libc=glibc node=14.18.1\n loaded from: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found