maybeJSX throws a fatal error instead of a warning
See original GitHub issueDescribe 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: https://github.com/vitejs/vite/blob/31f5ff3ef9ee071afa8cc66870e13e9753c3ab93/packages/vite/src/node/plugins/importAnalysis.ts#L198
Also see: https://github.com/vitejs/vite/discussions/6246
Reproduction
https://stackblitz.com/edit/vitejs-vite-9nnfuu?file=counter.js
System Info
System:
OS: macOS 12.5.1
CPU: (10) arm64 Apple M1 Max
Memory: 87.70 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
Browsers:
Chrome: 105.0.5195.125
Firefox: 104.0.1
Safari: 15.6.1
Used Package Manager
npm
Logs
17:34:04 [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
Plugin: vite:import-analysis
File: /home/projects/vitejs-vite-9nnfuu/foo/bar.svelte
1 | <script>
2 | let foo = 'bar';
3 | </script>
| ^
4 | <h1>this is a file that should be served as is</h1>
at formatError (file:///home/projects/vitejs-vite-9nnfuu/node_modules/vite/dist/node/chunks/dep-665b0112.js:40828:46)
at TransformContext.error (file:///home/projects/vitejs-vite-9nnfuu/node_modules/vite/dist/node/chunks/dep-665b0112.js:40824:19)
at TransformContext.transform (file:///home/projects/vitejs-vite-9nnfuu/node_modules/vite/dist/node/chunks/dep-665b0112.js:37495:22)
at async Object.transform (file:///home/projects/vitejs-vite-9nnfuu/node_modules/vite/dist/node/chunks/dep-665b0112.js:41077:30)
at async loadAndTransform (file:///home/projects/vitejs-vite-9nnfuu/node_modules/vite/dist/node/chunks/dep-665b0112.js:37338:29)
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
PHP converts Warnings to Fatal Errors - Stack Overflow
Suddenly, PHP starts converting common warnings to fatal errors (and thus I'm getting 500's). Examples: Fatal error: Comments starting with '#' ...
Read more >Why is my site showing warnings/fatal errors? - SiteGround KB
Fatal errors and warnings can appear for many reasons. It may be a broken or misconfigured plugin or a theme or another misconfiguration...
Read more >PHP Errors: 4 Different Types (Warning, Parse, Fatal, and ...
Learn about the 4 types of errors in PHP (Warning Errors, Notice Errors, Parse Errors, and Fatal Errors) and fix your script.
Read more >PHP 8.0: @ Error Suppression operator does not silent fatal ...
For example, the unlink function emits a warning if the file does not exist, and calling it with the @ operator can suppress...
Read more >trigger_error - Manual - PHP
trigger_error — Generates a user-level error/warning/notice message ... If error_type is E_USER_ERROR then trigger_error throw FATAL ERROR and script ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, ideally Vite should return the raw file with
fetch('foo.svelte')
. But it’s not currently possible. Vite needs to pass svelte files to plugin pipeline when it’s imported (e.g.import('foo.svelte')
) and serve it as-isfoo.svelte
when it’s fetched. So Vite needs to differentiatefetch('foo.svelte')
andimport('foo.svelte')
by HTTP header or something. But there isn’t any (Sec-Fetch-Dest
is not supported by Safari yet.). For now, Vite currently assumes svelte files are imported and not fetched.I’ve come up with another idea. If you always need a raw file, a plugin like this might work as an workaround:
There’s slightly related discussion here: #9981.
This won’t work. Even if the plugin handling
?raw
returned the raw content withoutexport default
, the plugin after that plugin will try to parse that content as JS and the errors will happen.IMO this error is correct because plugin pipeline expects the content to be JS. The problem here is that
foo.svelte
is passed to plugin pipeline, even if it isfetch
ed and notimport
ed.