Skip to content

ESM Modules loading in main crash with unsupported url scheme #46614

@UndefinedOffset

Description

@UndefinedOffset

Preflight Checklist

Electron Version

35.1.5

What operating system(s) are you using?

Ubuntu

Operating System Version

Ubuntu 24.04.2

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

ESM modules should load even when not bundler (such as webpack) in packaged apps as they do when not packaged.

Actual Behavior

When a packaged application using commonjs that is not bundled attempts to load a ESM module that is in the asar file Electron crashes with an ERR_UNSUPPORTED_ESM_URL_SCHEME error in the main process. Note this only seems to affect packaged applications, when the application is not packaged it loads fine. I've also experienced this on Windows 10 as well so it doesn't seem to be just isolated to Ubuntu 24.04.

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file and data are supported by the default ESM loader. Received protocol 'electron:'
    at getSourceSync (node:internal/modules/esm/load:74:11)
    at defaultLoadSync (node:internal/modules/esm/load:172:32)
    at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:410:24)
    at new ModuleJobSync (node:internal/modules/esm/module_job:341:34)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:357:11)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1392:24)
    at Module._compile (node:internal/modules/cjs/loader:1543:5)
    at Module._extensions..js (node:internal/modules/cjs/loader:1722:10)
    at Module.load (node:internal/modules/cjs/loader:1296:32)
    at Module._load (node:internal/modules/cjs/loader:1115:12)

Testcase Gist URL

https://gist.github.com/b2e85840f148bd1e0b5eedae1d32ef86

Additional Information

This is potentially a similar issue to that of #46448.

Metadata

Metadata

Assignees

Labels

35-x-yESMbug 🪲has-repro-gistIssue can be reproduced with code at https://gist.github.com/platform/allstatus/confirmedA maintainer reproduced the bug or agreed with the feature

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions