Skip to content

maybeJSX throws a fatal error instead of a warning #10123

@benjamingwynn

Description

@benjamingwynn

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:

const maybeJSX = !isVue && isJSRequest(importer)

Also see: #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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions