No native build was found for the platform runtime error with electron

See original GitHub issue

How to use this library with webpack in the electron js app? I have an electron js application that uses ffi-napi as a native module. The app works well if I don’t include this library. And if I include this library in the app I’ve to modify node’s global __dirname to true i.e. in the webpack config file: node: {__dirname: true}. This works well in the development mode. But when I build installer then starting an app would throws a runtime error:

Error: No native build was found for platform=darwin arch=x64 runtime=electron abi=87 uv=1 libc=glibc node=14.16.0 electron=12.0.6 webpack=true

With a little bit research I found this library needs a node global __dirname to be set up but in production mode I’m clueless to find what path this library is expecting for. Or how to set correct path that this library needs in order to function properly? Any help would really be appreciated! Thanks.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

3reactions
raviSussolcommented, Jun 14, 2021

@ngiafeno You can either use allowlist key inside nodeExternals() function to exclude node modules using negation in regex from the bundle. Say, you want to exclude ffi-napi module from the bundle then:

const nodeExternals = require('webpack-node-externals');
module.exports = {
  externals: [nodeExternals({
    allowlist: [/^(?!(^(ffi-napi)$)).*$/i]
  })],
  ...
}

Or the simple of way of excluding node modules without using any plugins or libraries in the webpack:

externals: [
  function ({ _, request }, callback) {
    if (/^(ffi-napi)$/.test(request)) {
      // Externalize to a commonjs module using the request path
      return callback(null, 'commonjs ' + request);
    }
    callback(); // Continue without externalizing the import
  }
]
1reaction
raviSussolcommented, May 22, 2021

@abjagtap You need to exclude this library from the bundle. Use webpack-node-externals to do so. E.g;

const nodeExternals = require('webpack-node-externals');
module.exports = {
  externals: [nodeExternals()],
  ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error running in VSCode: No native build was found ... - GitHub
Error running in VSCode: No native build was found for platform=darwin arch=x64 runtime=electron abi=83 uv=1 libc=glibc node=14.16.1 #243.
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 >
webpack/webpack - Gitter
App threw an error during load Error: No native build was found for runtime=electron abi=73 platform=win32glibc arch=x64 at Function.load.path ...
Read more >
Native Node Modules | Electron
When in doubt, run electron-rebuild first. Make sure the native module is compatible with the target platform and architecture for your Electron app....
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 >

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