Sveltekit + Windows = ERR_REQUIRE_ESM
See original GitHub issueUsing this library with SvelteKit 1.0.0-next.115 on Windows gives the following error:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\quick-i18n-throwaway-demo-main\node_modules\svelte-intl-precompile\index.js
require() of ES modules is not supported.
require() of C:\quick-i18n-throwaway-demo-main\node_modules\svelte-intl-precompile\index.js from C:\quick-i18n-throwaway-demo-main\node_modules\vite\dist\node\chunks\dep-bc228bbb.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 C:\quick-i18n-throwaway-demo-main\node_modules\svelte-intl-precompile\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 nodeRequire (C:\quick-i18n-throwaway-demo-main\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:68707:17)
at ssrImport (C:\quick-i18n-throwaway-demo-main\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:68660:20)
at eval (C:\quick-i18n-throwaway-demo-main\src\routes\index.svelte:7:31)
at instantiateModule (C:\quick-i18n-throwaway-demo-main\node_modules\vite\dist\node\chunks\dep-bc228bbb.js:68693:166)
You can see the error on a Windows machine and using your repo: https://github.com/cibernox/quick-i18n-throwaway-demo - but oddly the error isn’t thrown on a remote Gitpod environment which is Linux I’m assuming - and you must be devving on a Mac is why you never came across this error? I’m so confused why Windows would spin this up as it seems yet another classic ESM-Vite challenging bug.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:31 (12 by maintainers)
Top Results From Across the Web
Nodejs ES Module Problems with SvelteKit app - Stack Overflow
I'm trying to host a simple nodejs sveltekit application on a Windows based azure app service, but cannot get the application to start...
Read more >FAQ • SvelteKit
Please see the Svelte FAQ and vite-plugin-svelte FAQ as well for the answers to questions deriving from those libraries. How do I use...
Read more >Why Is Animejs Throwing This Error On Build In The Sveltekit ...
SvelteKit : How to output build as single HTML file with inlined JS and CSS? ... doesn't work still throws Error [ERRREQUIREESM]: require...
Read more >unexpected token 'export' at object.compilefunction (node:vm ...
I have ran into this error when trying to build my SvelteKit app: ... Doesn't seem like e.code === ERRREQUIREESM as its not...
Read more >Does SvelteKit work on Windows? : r/sveltejs - Reddit
Does SvelteKit dev work well under Windows? Total noob so prolly missing something, but I just tried the init mantra (npm init... npm...
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
I would like to add some information I gathered. I’m not sure if my issue is directly related to this, but the error is quiet similar.
I’ve a setup with rollup and included svelte-intl-precompile in order to compile the translations beforehand. The issue on my specific use case was that during SSR svelte-intl-precompile gets loaded in esm mode, initialized by
"type": "module"
in the projectspackage.json
. By the looks of it svelte-intl-precompile or to better name it precompile-intl-runtime is not able to run in esm mode without an external bundler.There are two missing parts:
package.json
of precompile-intl-runtime.The second point is derived from the nodejs documentation which states:
The typescript compiler does not issue such output and therefore does not produce valid es modules. See microsoft/TypeScript/issues/42151 and microsoft/TypeScript/pull/42184. The recommended way is to ad the js extension already in the typescript files. Which is IMHO kind of confusing, but it works.
Maybe the svelte/vite/node handling on windows is minimal different on windows than on other OS and therefore produces this issues (only a wild guess). Could be that addressing the invalid esm module issues solves this issue as a side effect.
I’ve created a fork and applied the needed fixes, it’s over here for reference.
@cibernox I’ve gotten it to work by using the full path to import
import { init, getLocaleFromNavigator, addMessages } from '../../node_modules/svelte-intl-precompile';
whereas
import { init, getLocaleFromNavigator, addMessages } from 'svelte-intl-precompile';
throws the same error @vish01 is getting