-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
dev/build silently externalizes some dependencies, leading to runtime errors #7105
Comments
For comparison, if I forget to enable polyfills in SnowPack, it gives me nice errors like this:
|
@NfNitLoop I created a PR for this. :), See if it can solve your problem. |
That’s much better! My personal preference would be an error, that the user could then bypass with some configuration. Like: that way you can’t accidentally miss the message. However, a warning is a definite improvement over being silent! 😊 |
And of course, the nicest would be if Vite had a polyfillNode feature like Snowpack. It would make migrations from snowpack to Vite easier. But I think that’s a different ticket. 😊 |
This sounds like a big change. It's literally a feature rather than a bug? |
polyfills in vite core will never be a builtin functionality. |
I agree! That's why I said:
I'm OK with just adding warning messages.
In an ideal world, sure. But that's not the current state of npm packages in my experience. There are many old packages that work just fine in the browser if they're given a Anyway, as I said above, adding polyfills is a separate issue. For the scope of this issue, I'm happy with just adding some warnings/errors. I should elaborate:
... and they don't have obvious replacements. (Or, the thing I'm depending on, which depends on them, doesn't have an obvious/easy replacement.) At which point my choice becomes
|
The latest Vite version should have better warnings when using builtin modules in the browser. I believe the improvements came in Vite 3 |
Describe the bug
Vite has some resolver plugins that cause it to "externalize" some dependencies by name. Instead of giving an error at bundle/build time, the dependency is just dropped from the dependency graph.
vite/packages/vite/src/node/plugins/resolve.ts
Lines 239 to 241 in 88ded7f
This leaves you to get runtime errors when things run in the browser.
If Vite had errors (or even warnings) about this, the user could look for other libraries or polyfills to resolve the issue.
Reproduction
NfNitLoop/vite-issue@5150380
System Info
Used Package Manager
npm
Logs
When running
npm run build && npm run preview
:When running
npm run dev
:Validations
The text was updated successfully, but these errors were encountered: