-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
vite:define
plugin will replace module or path-name keyword in defines
#5616
Comments
Nuxt3 case, nuxt/bridge#204 |
Vite docs specifically warn about using
@antfu @pi0 closing this issue, as it is already tracked in nuxt/bridge#204 This define rule should be removed, let's see what that was trying to workaround, maybe it isn't needed anymore: |
@patak-js Indeed makes sense to be fixed on the Nuxt side but how do you suggest to shim BTW worth mentioning rollup's replace plugin uses escape to prevent some edge cases like this (https://github.com/rollup/plugins/blob/master/packages/replace/src/index.js#L44) |
shimming can be done in html file by writing |
issue should maybe be reopened again to improve |
About the process, and other node builtins in general, it is an issue for Vite in general. I think the ideal would be to invest time in getting something like https://github.com/snowpackjs/rollup-plugin-polyfill-node to work smoothly in Vite (this was working for Snowpack IIUC, so I think it should be an option). I think the community hasn't spent time in this because most of these cases end up being solved by switching an old dependency to a modern alternative, or by fixing the dep so they don't depend on node builtins. About improving the regex, we have been merging small changes there. If there is a PR, we can check it with Evan. @Niputi the paths are replaced in import statements, no? In that case, I think it is working as expected |
@patak-js it was this issue I remembered #4796 which seemed like |
Thanks for the pointers @patak-js @Niputi. For now, I decided to remove
This seems a good idea. I would polyfill using
I would be more than happy to help with this. With Nuxt 3 and Nitro, we had to create a Node.js shimming framework unjs/unenv. It basically returns a framework agnostic preset of shims and polyfills. It already covers common use cases but I tend to increase Node.js coverage including Before starting unenv, I tried We plan to use unenv for Nuxt 3 with vite soon (nuxt/nuxt#12786) will let you know how it goes and (probably adding Regarding this issue, I let you judge worth improving on vite's side or not. The behavior seems expected for replacement -- however vite could cover more edge cases and bade replacements out of the box on the other hand, it can add more codebase complexity. |
https://github.com/unjs/unenv looks great @pi0, and it would be great for Vite if there was an easy way to drop it in as a Vite plugin or something similar so we could recommend if users are facing issues with their deps. I still think that long term we should keep pushing for the ecosystem to fix this in each package, but this could alleviate a lot of temporal pain. |
@patak-js , As @pi0 mentioned, I recommend vite to add dev mode warning for define’s key that contain some private or inside keywords in JavaScript. That is if no plan to make this replacement smoothly. |
Describe the bug
if some lib, folder or file-name have some keyword defined in
define
property, and runvite build
will casue[vite]: Rollup failed to resolve import
error.After checked source code and found some casue on follow picture.
Reproduction
open this link https://stackblitz.com/edit/vite-hxw2x7 and see
Terminal
outputSystem Info
The text was updated successfully, but these errors were encountered: