Open dsanders11 opened 5 years ago
Hi @dsanders11!
Could you create a repro repo to help me narrow things down?
@jdalton, here you go: https://github.com/dsanders11/electron-quick-start/tree/dynamic-import-native-module-crash
You can run npm run rebuild
to see the go-right case when the native module is built for Electron.
Any workarounds / fixes for this?
At first I thought this was a regression of #692, but it seems like it's a different issue.
I don't have a tight reproduce case, but I can describe the general setup and what I think is happening.
usb
) but don't runelectron-rebuild
. The module will have an error about being the wrong Node version when you try to run Electron, if usingrequire
.esm
and do a dynamic import for the module (import('usb')
). Run Electron, dev tools disconnect and the process hangs.electron-rebuild
, run Electron again, all works.So, it appears dynamic import is not gracefully handling the error about wrong Node version for the native module. Even if I try to catch any error on dynamic import, it still fails, which means the promise isn't throwing:
import('usb').then(module => console.log(module)).catch('error')
I'm not positive it's only related to native modules, but that's how I ran into it, and I unfortunately don't have time to fully run it down to a small reproduce case.
I did try simply making a module with a single line (
throw new Error('fail')
) and using dynamic import on that module. It doesn't crash, but it does log an uncaught exception rather than using thecatch
block. Not sure if that's working as expected, my intuition would have been that it should trigger the catch block.