Error [ERR_REQUIRE_ESM]: Must use import to load ES Module @preact\preset-vite when scaffolding vanilla preact
See original GitHub issueWhen using npm init vite
with the preact
framework and preact
(vanilla js) variant, I get the following error when starting the development server after npm install:
error when starting dev server:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: E:\Javascript\starter-vite-preact\node_modules\@preact\preset-vite\dist\index.js
require() of ES modules is not supported.
require() of E:\Javascript\starter-vite-preact\node_modules\@preact\preset-vite\dist\index.js from E:\Javascript\starter-vite-preact\vite.config.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 index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from E:\Random42\Javascript\starter-vite-preact\node_modules\@preact\preset-vite\package.json.
at Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
at Object.require.extensions.<computed> [as .js] (E:\Javascript\starter-vite-preact\node_modules\vite\dist\node\chunks\dep-36bf480c.js:77286: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 Object.<anonymous> (E:\Random42\Javascript\starter-vite-preact\vite.config.js:30:37)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.require.extensions.<computed> [as .js] (E:\Javascript\starter-vite-preact\node_modules\vite\dist\node\chunks\dep-36bf480c.js:77283:20)
at Module.load (internal/modules/cjs/loader.js:928:32)
Deps versions are
"preact": "^10.5.13"
"@preact/preset-vite": "^2.0.0",
"vite": "^2.5.4"
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
ESLint - Error: Must use import to load ES Module
I think the problem is that you are trying to use the deprecated babel-eslint parser, last updated a year ago, which looks like...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@marvinhagemeister Thank You!
Same here. The error goes away after adding
"type": "module"
in package.json, however VSCode started to complain now (Cannot find module ‘@preact/preset-vite’ or its corresponding type declarations.).There was an attempt to update vite templates (https://github.com/vitejs/vite/pull/4293) but it has been closed.