-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
SSR Externals False Positive on Windows #2393
Comments
From sveltejs/kit#1549: Describe the bug import { debounce } from 'lodash-es'
//...debounce using it but I'm getting the below error. Logs
To Reproduce Information about your SvelteKit Installation: Diagnostics
Severity |
@yyx990803 @Shinigami92 what is the code I can inspect to understand what is going on? |
I'm getting this error by simply trying to make an import to an (ESM) package I wrote from > vite
failed to load config from /home/rhengles/github/vite-test-app/vite.config.ts
error when starting dev server:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/rhengles/github/vite-plugin-vue-mfc/index.mjs
at Module.load (internal/modules/cjs/loader.js:861:11)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/rhengles/github/vite-test-app/vite.config.ts:31:45)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.require.extensions.<computed> [as .ts] (/home/rhengles/github/vite-test-app/node_modules/vite/dist/node/chunks/dep-6b5f3ba8.js:70305:20)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19) |
I'm getting this error on svelte-kit: sveltejs/kit#928 The package's package.json file:
As a workaround i got it to work by adding this to vite config:
|
Having the same issue on |
just for googlers: for svelte/kit (next153) and layerrcake with d3 graphics library i had similar error until i added the d3 packages to the svette.config.js as mentioned above : const config = {
kit: {
vite: {
ssr: {
noExternal: ["d3-scale", "d3-array", "d3-time-format", "d3-time", "d3-shape"] But i have noi clue what the sideeffects of that are... :/ EDIT: |
Describe the bug
Part of the heuristic for determining if a dependency should be externalized for SSR is to compare the "resolved ESM entry point and its default Node entry point". That comparison happens here:
vite/packages/vite/src/node/ssr/ssrExternal.ts
Line 67 in 5095e04
The path
requireEntry
comes fromrequire.resolve
which is not normalized. On Windows the pathentry
(which is normalized) has POSIX path separators andrequireEntry
has Windows path separators. This leads to a false positive, thinking the package has a cjs distribution which then fails at runtime.Simply using Vite's path normalization utility on
requireEntry
also doesn't quite work as, at least in my case, the paths end up with slightly different casing:"C:\..."
vs"c:\..."
Reproduction
https://github.com/rturnq/solid-hackernews
System Info
vite
version: 2.0.5Logs (Optional if provided reproduction)
The text was updated successfully, but these errors were encountered: