Skip to content
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

[@vitejs/plugin-vue-jsx] importing vue sfc with jsx does not work if custom queries added #23

Open
7 tasks done
dotoleeoak opened this issue Jun 5, 2022 · 4 comments

Comments

@dotoleeoak
Copy link

dotoleeoak commented Jun 5, 2022

Describe the bug

In Nuxt 3, custom queries are added to id when importing files under pages directory, such as
/pages/index.vue?vue&type=script&lang.jsx&macro=true (in this case, macro=true)
In this case, vue jsx plugin does not acknowledge the context and throws an error.

More info: nuxt/nuxt#13435
Probably related to PR vitejs/vite#7121

Reproduction

https://stackblitz.com/edit/vitejs-vite-uo2vwz

System Info

System:
  OS: Linux 5.16 Ubuntu 20.04.4 LTS (Focal Fossa)
  CPU: (16) x64 AMD EPYC 7B13
  Memory: 33.38 GB / 62.80 GB
  Container: Yes
  Shell: 5.0.17 - /bin/bash
Binaries:
  Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
  Yarn: 3.2.1 - ~/.nvm/versions/node/v16.15.0/bin/yarn
  npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm

Used Package Manager

yarn

Logs

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.


 WARN   [SSR] Error transforming /pagess/index.vue?vue&type=script&setup=true&lang.jsx&macro=true: 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.

   at formatError (node_modules/vite/dist/node/chunks/dep-59dc6e00.js:38663:46)
   at TransformContext.error (node_modules/vite/dist/node/chunks/dep-59dc6e00.js:38659:19)
   at TransformContext.transform (node_modules/vite/dist/node/chunks/dep-59dc6e00.js:56777:22)
   at async Object.transform (node_modules/vite/dist/node/chunks/dep-59dc6e00.js:38900:30)
   at async doTransform (node_modules/vite/dist/node/chunks/dep-59dc6e00.js:55857:29)

Validations

@sapphi-red
Copy link
Member

IIUC extension needs to be at the end of id. So /pages/index.vue?vue&type=script&lang.jsx&macro=true needs to be /pages/index.vue?vue&type=script&macro=true&lang.jsx.

refs: vitejs/vite#6912 (comment)

@danielroe
Copy link

We can likely work around this in Nuxt - but would you welcome a PR to change the behaviour in Vite so that it isn't dependent on query order?

@sapphi-red
Copy link
Member

sapphi-red commented Jun 11, 2022

Probably no. Even if vue-jsx plugin accepted it, plugins which assume .jsx to be at the end (or at the end after removing query) will exist and they will not work.
But I'm not certain about this.

@bluwy
Copy link
Member

bluwy commented Jun 13, 2022

I'd second working around it in Nuxt at the meantime. There's a solution of using meta.vite.lang to specify the extension like:

https://github.com/vitejs/vite/blob/dc0022529610f159d5e635087307ac109746d830/packages/plugin-vue/src/main.ts#L229-L233

But this isn't commonly used yet, and it would break the ecosystem otherwise. I agree though that a behaviour like this isn't great at a glance, but I'd imagine a migration over to meta.vite.lang and then dropping checking extensions in Vite 4 would be the ideal path forward.

(I haven't considered other consequence of dropping the extensions check yet)

@patak-dev patak-dev transferred this issue from vitejs/vite Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants