-
-
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
maybeJSX throws a fatal error instead of a warning #10123
Comments
Thanks for the reply!
We tried this but the file seems to always serve with a wraper for ESM compatability. Is there a way to serve from Vite without the If not, we can use the proxy option to get our backend web server to handle serving these files, but it'd be nice to do it through Vite for its various features when resolving paths and the like. |
I forgot about it. A bit hacky but I think this would work. const res = await fetch('./foo.svelte?raw')
const content = await res.text()
const m = content.match(/^export default ("[^]+")$/)
const realContent = m ? /* dev */ JSON.parse(m[1]) : /* build */ content |
Although this would work, ideally we'd just have the server serve the file as-is, is this not possible with Vite currently? As eluded to, we're working on a Svelte file editor, so it has a bundler on the frontend that needs to get src files as-is (including resolving *.svelte content from node_modules), we can add this We can use the I'm a bit amiss as to why this behaviour is different between Thanks again for all your help! VIte has been an incredible addition to our stack 🎉 |
Yes, ideally Vite should return the raw file with
I've come up with another idea. If you always need a raw file, a plugin like this might work as an workaround: const plugin = {
name: 'plugin',
configureServer(server) {
server.middleware.use(async (req, res, next) => {
if (req.url.endsWith('.svelte')) { // needs to handle more precisely
const content = await fs.readFile(path.resolve(root, req.url))
res.end(content)
return
}
next()
})
}
} |
Thank you for the workarounds and insight, the issue makes a lot of sense now! Is there an existing Vite issue/discussion open for
I think it would make sense to add the relevant functionality for Happy to fork this off into another issue if one doesn't exist to avoid confusion with the |
There's slightly related discussion here: #9981.
This won't work. Even if the plugin handling
IMO this error is correct because plugin pipeline expects the content to be JS. |
Describe the bug
There should be some environmental variable to skip the
maybeJSX
variable bailing, or it should be a warning.This flags incorrectly for us, as we're specifically serving Svelte files without the Svelte plugin for integration with a file editor.
This comes from line 198 of importAnalysis.ts:
vite/packages/vite/src/node/plugins/importAnalysis.ts
Line 198 in 31f5ff3
Also see: #6246
Reproduction
https://stackblitz.com/edit/vitejs-vite-9nnfuu?file=counter.js
System Info
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: