-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dynamic import not working inside asar #249
Comments
Also encountered this today. The specific line of code that fails only in the asar is...
|
Check this out and the "Things that were fixed" section. This is a solution for ESM imports but also fixes I believe the problems with dynamic imports in asar. electron/electron#37535 |
How did you solve the issue with nested dependencies? I've tried an artifact of the pull request you referred, and while a lot of ESM things now work, it seems like it doesn't respect the exports section of the package.json files in the ASAR. |
nklayman/vue-cli-plugin-electron-builder/issues/1622 electron/electron/issues/21457 electron/asar/issues/249 Fix desktop applications failing with following error: ``` A JavaScript error occurred in the main process Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_privacSXvQfc/resources/app.asar/index.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /tmp/.mount_privacSXvQfc/resources/app.asar/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at f._load (node:electron/js2c/asar_bundle:2:13330) at node:electron/js2c/browser_init:2:123492 at node:electron/js2c/browser_init:2:123695 at node:electron/js2c/browser_init:2:123699 at f._load (node:electron/js2c/asar_bundle:2:13330) ```
nklayman/vue-cli-plugin-electron-builder/issues/1622 electron/electron/issues/21457 electron/asar/issues/249 Fix desktop applications failing with following error: ``` A JavaScript error occurred in the main process Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_privacSXvQfc/resources/app.asar/index.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /tmp/.mount_privacSXvQfc/resources/app.asar/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at f._load (node:electron/js2c/asar_bundle:2:13330) at node:electron/js2c/browser_init:2:123492 at node:electron/js2c/browser_init:2:123695 at node:electron/js2c/browser_init:2:123699 at f._load (node:electron/js2c/asar_bundle:2:13330) ```
nklayman/vue-cli-plugin-electron-builder/issues/1622 electron/electron/issues/21457 electron/asar/issues/249 Fix desktop applications failing with following error: ``` A JavaScript error occurred in the main process Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_privacSXvQfc/resources/app.asar/index.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /tmp/.mount_privacSXvQfc/resources/app.asar/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at f._load (node:electron/js2c/asar_bundle:2:13330) at node:electron/js2c/browser_init:2:123492 at node:electron/js2c/browser_init:2:123695 at node:electron/js2c/browser_init:2:123699 at f._load (node:electron/js2c/asar_bundle:2:13330) ```
nklayman/vue-cli-plugin-electron-builder/issues/1622 electron/electron/issues/21457 electron/asar/issues/249 Fix desktop applications failing with following error: ``` A JavaScript error occurred in the main process Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_privacSXvQfc/resources/app.asar/index.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /tmp/.mount_privacSXvQfc/resources/app.asar/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at f._load (node:electron/js2c/asar_bundle:2:13330) at node:electron/js2c/browser_init:2:123492 at node:electron/js2c/browser_init:2:123695 at node:electron/js2c/browser_init:2:123699 at f._load (node:electron/js2c/asar_bundle:2:13330) ```
nklayman/vue-cli-plugin-electron-builder/issues/1622 electron/electron/issues/21457 electron/asar/issues/249 Fix desktop applications failing with following error: ``` A JavaScript error occurred in the main process Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_privacSXvQfc/resources/app.asar/index.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /tmp/.mount_privacSXvQfc/resources/app.asar/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at f._load (node:electron/js2c/asar_bundle:2:13330) at node:electron/js2c/browser_init:2:123492 at node:electron/js2c/browser_init:2:123695 at node:electron/js2c/browser_init:2:123699 at f._load (node:electron/js2c/asar_bundle:2:13330) ```
nklayman/vue-cli-plugin-electron-builder/issues/1622 electron/electron/issues/21457 electron/asar/issues/249 Fix desktop applications failing with following error: ``` A JavaScript error occurred in the main process Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_privacSXvQfc/resources/app.asar/index.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /tmp/.mount_privacSXvQfc/resources/app.asar/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at f._load (node:electron/js2c/asar_bundle:2:13330) at node:electron/js2c/browser_init:2:123492 at node:electron/js2c/browser_init:2:123695 at node:electron/js2c/browser_init:2:123699 at f._load (node:electron/js2c/asar_bundle:2:13330) ```
nklayman/vue-cli-plugin-electron-builder/issues/1622 electron/electron/issues/21457 electron/asar/issues/249 Fix desktop applications failing with following error: ``` A JavaScript error occurred in the main process Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_privacSXvQfc/resources/app.asar/index.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /tmp/.mount_privacSXvQfc/resources/app.asar/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at f._load (node:electron/js2c/asar_bundle:2:13330) at node:electron/js2c/browser_init:2:123492 at node:electron/js2c/browser_init:2:123695 at node:electron/js2c/browser_init:2:123699 at f._load (node:electron/js2c/asar_bundle:2:13330) ```
nklayman/vue-cli-plugin-electron-builder/issues/1622 electron/electron/issues/21457 electron/asar/issues/249 Fix desktop applications failing with following error: ``` A JavaScript error occurred in the main process Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_privacSXvQfc/resources/app.asar/index.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /tmp/.mount_privacSXvQfc/resources/app.asar/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at f._load (node:electron/js2c/asar_bundle:2:13330) at node:electron/js2c/browser_init:2:123492 at node:electron/js2c/browser_init:2:123695 at node:electron/js2c/browser_init:2:123699 at f._load (node:electron/js2c/asar_bundle:2:13330) ```
nklayman/vue-cli-plugin-electron-builder/issues/1622 electron/electron/issues/21457 electron/asar/issues/249 Fix desktop applications failing with following error: ``` A JavaScript error occurred in the main process Uncaught Exception: Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/.mount_privacSXvQfc/resources/app.asar/index.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /tmp/.mount_privacSXvQfc/resources/app.asar/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). at f._load (node:electron/js2c/asar_bundle:2:13330) at node:electron/js2c/browser_init:2:123492 at node:electron/js2c/browser_init:2:123695 at node:electron/js2c/browser_init:2:123699 at f._load (node:electron/js2c/asar_bundle:2:13330) ```
- Switch from deprecated Vue CLI plugin to `electron-vite` (see nklayman/vue-cli-plugin-electron-builder#1982) - Update main/preload scripts to use `index.cjs` filenames to support `"type": "module"`, resolving crash issue (#233). This crash was related to Electron not supporting ESM (see electron/asar#249, electron/electron#21457). - This commit completes migration to Vite from Vue CLI (#230). Structure changes: - Introduce separate folders for Electron's main and preload processes. - Move TypeHelpers to `src/` to mark tit as accessible by the rest of the code. Config changes: - Make `vite.config.ts` reusable by Electron configuration. - On electron-builder, use `--publish` flag instead of `-p` for clarity. Tests: - Add log for preload script loading verification. - Implement runtime environment sanity checks. - Enhance logging in `check-desktop-runtime-errors`.
Should be fixed by electron/electron#40221. I'm closing this for now since the issue is not on |
- Switch from deprecated Vue CLI plugin to `electron-vite` (see nklayman/vue-cli-plugin-electron-builder#1982) - Update main/preload scripts to use `index.cjs` filenames to support `"type": "module"`, resolving crash issue (#233). This crash was related to Electron not supporting ESM (see electron/asar#249, electron/electron#21457). - This commit completes migration to Vite from Vue CLI (#230). Structure changes: - Introduce separate folders for Electron's main and preload processes. - Move TypeHelpers to `src/` to mark tit as accessible by the rest of the code. Config changes: - Make `vite.config.ts` reusable by Electron configuration. - On electron-builder, use `--publish` flag instead of `-p` for clarity. Tests: - Add log for preload script loading verification. - Implement runtime environment sanity checks. - Enhance logging in `check-desktop-runtime-errors`.
I need to use esm only package (lowdb). To do this I use dynamic import to workaround electron's cjs-only. It works fine in dev build. After bundling app to asar this fails, because process cannot resolve import from lowdb. lowdb package featuring exports maps, so it might be related to the fact that required module file differs from import uri (resolved via export map).
The text was updated successfully, but these errors were encountered: