nextron: cannot use native modules?
When running npm run dev, I’m getting this from node-serialport:
The module <path/to/bindings> was compiled with NODE_MODULE_VERSION 70. This version of Node.js requires NODE_MODULE_VERSION 72
I’ve tried installing electron and using electron-rebuild, upgrading all my dependencies, and trying everything I could from the official tutorial but still get this message. Honestly, I have no idea how Electron is getting launched using npm run dev…
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 25 (12 by maintainers)
Commits related to this issue
- Add a missing config target (electron-renderer) in the next.config.js #38 — committed to saltyshiomix/nextron by saltyshiomix 5 years ago
@saltyshiomix’s PR fixes the issue!
I found that
electron-rebuildisn’t necessary, though. See https://github.com/boneskull/nextron-serialport/commit/c16805ee1a352973154d448c24c9110164ba6a8fTL;DR: configure
electron-builderto have optionbuildDependenciesFromSource = trueI guess I can put that config in
electron-builder.ymlinstead, but same idea.That’s also the conclusion I’ve come to. thanks for helping!
I think it’s the best way to use server scripts whithin the main process if we want to use Next.js as the renderer process.
serialport is a Node.js module. It can’t be used in the browser.
There’s nothing special about
serialportother than it contains a native module (specifically, @serialport/bindings).I don’t think that’s right. As of Electron v5, using
new BrowserWindow({webPreferences: {nodeIntegration: true}})enables use of Node.js modules. IIRC prior to this version, it was enabled by default.For example, I can do this in an
index.htmlloaded byBrowserWindow#load:Result:
I think because in
nextron, the Next.js development server is actually serving the pages used by the renderer process, this is not possible to do. Does this sound right?@saltyshiomix see https://github.com/boneskull/nextron-serialport for example
The steps I took here:
npx nextron initto create a new thingnpm installin resulting dirserialportas a dependency, containing the native module)importstatement to source codenpm run devwhich shows the first errorelectronVersion: 5.0.6toelectron-builder.ymlnpx electron-builder install-app-depsresults in the first paste abovenpx electron-rebuild; completes successfully, but results in the second error shown aboveI have never used
electron-rebuild, butelectron-builderalways worked for me.try
electron-builder install-app-deps, if you haven’t already. Or add it as apostinstallscript