Skip to content
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

Must use import to load ES Module #59

Open
jctaoo opened this issue Jan 24, 2022 · 1 comment
Open

Must use import to load ES Module #59

jctaoo opened this issue Jan 24, 2022 · 1 comment

Comments

@jctaoo
Copy link
Owner

jctaoo commented Jan 24, 2022

Error when using pure esm module like chalk.

App threw an error during load
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/junso/Projects/rim/node_modules/chalk/source/index.js
require() of ES modules is not supported.
require() of /Users/junso/Projects/rim/node_modules/chalk/source/index.js from /Users/junso/Projects/rim/node_modules/.electron-run/app/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /Users/junso/Projects/rim/node_modules/chalk/source/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/junso/Projects/rim/node_modules/chalk/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1169:13)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12738)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/junso/Projects/rim/node_modules/.electron-run/app/index.js:128:31)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
    at Module.load (internal/modules/cjs/loader.js:992:32)
@wxhccc
Copy link

wxhccc commented Mar 14, 2022

electron项目用的高版本v8内核,可以考虑生成index.mjs文件。可以原生支持esm。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants