这是indexloc提供的服务,不要输入任何密码
Skip to content

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module #352

@PuruVJ

Description

@PuruVJ

I just created a project, set up tsup to be the bundler, and when I run npx tsup or npm run build, it gives me this error

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: P:\svelte-hotkeys\tsup.config.bundled.js
require() of ES modules is not supported.
require() of P:\svelte-hotkeys\tsup.config.bundled.js from P:\svelte-hotkeys\node_modules\tsup\dist\chunk-BNJB64XR.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 tsup.config.bundled.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from P:\svelte-hotkeys\package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at __require (P:\svelte-hotkeys\node_modules\tsup\dist\chunk-BNJB64XR.js:27:12)
    at readConfig (P:\svelte-hotkeys\node_modules\tsup\dist\chunk-AUI5UK2M.js:2021:47)
    at bundleConfig (P:\svelte-hotkeys\node_modules\tsup\dist\chunk-AUI5UK2M.js:2053:20)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async loadTsupConfig (P:\svelte-hotkeys\node_modules\tsup\dist\chunk-AUI5UK2M.js:2006:20)

Apparently, the issue arises because of the type: module in my package json. Removing that fixes the problem.

Here's the repo where the problem is occuring https://github.com/PuruVJ/svelte-hotkeys

Thanks for your great work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions