Hi all! Astro maintainer here. I'm working on JSON support for our data collections format, and I'm attempting to load the module as a transformed JS file using the ?astroContent flag (i.e. import specialParsing from './data.json?astroContent'). Unfortunately, I've found that Vite will transform json even when a flag is present (and even when I have a plugin overriding the load of json files). so I attempt to turn .json?astroContent into a JS module, and Vite later tries to parse this as JSON (and fails). Is there any way around this? Or will I need to ditch ?flags and use a virtual:module prefix instead?
#Vite transforms .json even when ?flag is present
1 messages · Page 1 of 1 (latest)
Update: was hoping a &lang.js query param would help to mask to file type. Sadly getting the same result 😕
Ah, found the regex for this in the source. Looks like it'll match even with virtual modules or lang.X flags. Only way around it is to append .js to the file path via resolveId, or use commonjs-external as a hack
https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/json.ts#L29
I'd submit a PR, but I have a feeling many repos depend on this handling for .json files 😅
maybe you're hitting https://github.com/vitejs/vite/issues/8523, i had a pr a long time ago, but it hadn't got discussed in a team meeting yet: https://github.com/vitejs/vite/pull/8933