Can't import native modules from release/app in preload.ts

2
open
BarakChamo
BarakChamo
Posted 3 months ago

Can't import native modules from release/app in preload.ts #3212

Prerequisites

Expected Behavior

Importing native module packages installed in release\app should work, as described in:

Current Behavior

I'm trying to setup serialport and usb-detection in the preload.ts script and expose a few handlers to the renderer process. I followed instructions on installing native modules, ran the postinstall a few times to verify rebuild and linking and made sure the node_modules folder is linked in the source folder.

However, when running the project, the packages are not found.

This is the console error for example in Electron:

Unable to load preload script: D:\dev\...\.erb\dll\preload.js
(anonymous) @ VM113 renderer_init:73
VM113 renderer_init:73 Error: Cannot find module 'serialport'
Require stack:
- D:\dev\...\.erb\dll\preload.js

Steps to Reproduce

  1. Clone the latest electron-react-boilerplate
  2. Install serialport inside release\app
  3. require serialport in preload script

Context

I'm trying to communicate with custom USB devices.

Your Environment

  • Node version : 18.1.0, tried 16.3.2, no change
  • electron-react-boilerplate version or branch : fresh install from main
  • Operating System and version : Win 11
BarakChamo
BarakChamo
Created 3 months ago

update:

Installing serialport to the root folder fixed this issue, which now moved on to usb-detection.

The serialport library seems to not have direct native modules so I wasn't getting to console warning, but I did with usb-detction

It seems whatever mechanism exists to make these externals from release\app available is not working.

fmtrack
fmtrack
Created 3 weeks ago

I tried to instal leveldown and rxdb I am also having the same issue