-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cannot use createRequire with adapter-node #2566
Comments
Why not just write: import * as myLibrary from "some-commonjs-library" |
@JeanJPNM this doesn't work always,... or better said, this work only sometimes. I think, createRequire should work. |
Why wouldn't it work? As far as I know you can import commonjs modules inside esm ones. |
Also, in the built app you don't actually use |
depends how it's exported, on configuration of package, and if it depend on another esm or commonjs package,... and it really doesn't work in all situations. That's why createRequire exist in first place. |
Poking around about this transformation, I found evanw/esbuild#208 - I wonder whether having the target format in SvelteKit's configuration that it sends to Vite hardcoded to |
fwiw, I cannot use import with this commonjs module. It is being linked locally as an npm package, but that should not matter
|
@andykais Linking an npm package locally matters. Vite treats them as source code (code that you write), and would expect that npm package to be exported with ESM code. If it's not possible, the way around it is to explicitly add that library to |
I dont think thats true, or maybe Im not using the right terminology. I am linking this package via |
@andykais Vite has special handling for linked dependencies. |
Pretty sure #2566 (comment) is correct — this works in the current version, but fails if I override |
Describe the bug
the builtin method
createRequire
works fine in development, but fails when building a production app with adapter-node.Reproduction
any esm file with a require statement like the following will fail to build/preview.
I have the default svelte.config.js with an adapter-node added.
running
npm run build
will error out.Logs
The text was updated successfully, but these errors were encountered: