electron-vite-react: How to use ESM modules in main process? Dynamic import broken after build
I’m just trying to use execa in the main process with:
import { execaCommand } from "execa"
But I hit the Error [ERR_REQUIRE_ESM]: require() of ES Module issue.
If I switch to a dynamic import:
const { execaCommand } = await import("execa")
This works fine with npm run dev, BUT breaks when building with npm run build with the following error:
(I’m using electron-unhandled to capture the error)
Error: ENOTDIR: not a directory, stat '/Users/johnlindquist/dev/electron-vite-react/release/2.1.0/mac-arm64/electron-vite-react.app/Contents/Resources/app.asar/dist-electron/main/node_modules/execa'
Thanks for any help!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 24 (11 by maintainers)
@caoxiemeihao Awesome, thanks for hunting that down 💛
@caoxiemeihao Awesome, you rock! 🤘
I’ll try this tomorrow, been AFK a couple days.