-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Named export not found for an ESM module when running svelte-kit build #1498
Comments
I can't quite figure out what's going on or how this is supposed to work. Maybe someone who knows more about the Node module resolution would know. I don't think it's related to Vite. The Vite build seems to have already completed successfully. And the stack trace seems to be coming from Node itself You can see that it happens during prerendering if you change
Node really wants to load the CommonJS version for some reason. The code for the Node.js module resolution is here: https://github.com/nodejs/node/blob/master/lib/internal/modules/esm/resolve.js By looking at it a bit I figured out that you can make it work with:
That's not an ideal |
Thanks @benmccann |
Had the same issue with the
The solution is as suggested to use the default export, so instead of: import { set } from 'monolite';
set(...); Use the default export: import monolite from 'monolite';
monolite.set(...); |
This issue occurs when an adapter is added to the config (tested with netlify), and I run
npm run build
.So far I've seen the error from multiple dependencies, but my testing of the issue has focussed on https://github.com/devlato/async-wait-until/
A above dependency ships an ESM formatted JS module.
The problem is that even though the module has a named export and is ESM, the named export is not detected, and the file is recognised as being CommonJS.
If I use the default export, there are no issues:
However, if I use a named export:
Then I get the following error on
npm run build
:To reproduce:
Clone this repo: https://github.com/benwoodward/sveltekit-named-export-issue-repro, and then swap the default export import for one of the named export imports, and then run
npm run build
I have tested this with node versions 12.22.1, 14.16.1, and 16.1.0.
The text was updated successfully, but these errors were encountered: