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-rebuild
isn’t necessary, though. See https://github.com/boneskull/nextron-serialport/commit/c16805ee1a352973154d448c24c9110164ba6a8fTL;DR: configure
electron-builder
to have optionbuildDependenciesFromSource = true
I guess I can put that config in
electron-builder.yml
instead, 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
serialport
other 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.html
loaded 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 init
to create a new thingnpm install
in resulting dirserialport
as a dependency, containing the native module)import
statement to source codenpm run dev
which shows the first errorelectronVersion: 5.0.6
toelectron-builder.yml
npx electron-builder install-app-deps
results in the first paste abovenpx electron-rebuild
; completes successfully, but results in the second error shown aboveI have never used
electron-rebuild
, butelectron-builder
always worked for me.try
electron-builder install-app-deps
, if you haven’t already. Or add it as apostinstall
script