-
-
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 plugins drop import attributes/assertions property only from src not node_modules #14674
Comments
⁸As i was writing this 5.0.0-beta.10 landed with rollup v4 (#14508) i updated the example to include it. The issue still persists also rollup v4 will transform existing assert props to the attribute property for backwards compatibility |
I dug into this a little bit and I think the problem is that Vite doesn't always use Rollup's
Which means that we would need es-module-lexer to support them. Does this sound right @patak-dev @bluwy ? I'd be willing to poke at es-module-lexer and see what it takes to add. |
Ah, it looks like es-module-parser might already support them. guybedford/es-module-lexer#150 |
I have a spike of this being added to resolveId |
Pull request is up: #15654 |
I noticed is that import attributes are incorrectly removed when import tlds from "tlds" with {type: "json"}; becomes import tlds from "tlds"; I'm builing a node lib in vite and import attributes must be preserved in the compiled output as otherwise node can not load json modules in ESM. Running esbuild alone with the |
Here's the related esbuild issue which confirms it should be working with |
Yeah, I assume this specific bug will be fixed with the next vite release that upgrades esbuild to 0.21.x. So no, it was not a vite bug as I initially assumed. |
Actually, vite removes import attributes vite/packages/vite/src/node/plugins/importAnalysis.ts Lines 494 to 497 in 3af02bd
I have been working on a new PR based on @matthewp work to fix errors. |
Describe the bug
Vite has had a few issues opened about plugins not being able to access import assertions and have been closed due to import assertions being depreciated for import attributes #12140 & #10633 . the problem is this issue is only for direct project code any import that goes through node_modules will have access to these assertions/attributes. while the same code ran directly through rollup (v3 and v4) will have the attributes/assertions in project code and node_modules
This can be seen in vite's playground/import-assertion. by adding a simple vite config to that playground that logs options.
when running
vite build
it will show that the assert in index.html will not have any assertions but in import-assertion-dep/index.js it will have the assertionimport attributes will be coming in typescript 5.3 and are already in rollup v4 without this plugin authors won't be able to leverage this new feature. i have also tried this with #14508 and it also had the same issues
i have created a example repo with a plugin to check for these assertions/attributes. it has rollup 3.x 4.x vite 4.x and 5.0.0-beta.8 both, versions of rollup handle this properly and both versions of vite fail.
Reproduction
https://stackblitz.com/~/github.com/arbassett/vite-attributes-assert-issue
Steps to reproduce
run pnpm build
System Info
Used Package Manager
pnpm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: