-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
JSX import source goes wrong when using Astro with React + SolidJS + TypeScript #4590
Comments
I think the problem is that when there is more than one JSX renderer configured, Astro attempts to detect the import source by:
Heres the code where that happens: astro/packages/astro/src/vite-plugin-jsx/index.ts Lines 204 to 226 in 7310e8a
This breaks down in your Solid example, because the If you add an import that is needed at runtime (e.g. |
Thanks for the insight. Is this also the cause for the last 2 bullet points of this report? Do you see value in having Astro read This would make working with Astro in a monorepo with separate workspaces for React and SolidJS components easier because it prevents the need to tag every single component with a pragma. Relying on an import statement that might not always exist for basic components seems like an anti-pattern to be honest. |
I believe so. All components whose
Yeah, that seems like a reasonable behavior to me. The Astro docs suggest that the However, the error message that is thrown recommends setting an import or adding a pragma comment when there are multiple renderers:
We'll need some clarification about what the intended behavior should be here. |
I think this might be a deeper problem. That error is coming from Vite which is pretty unexpected. |
This PR will read from the tsconfig to determine which jsxImportSource to use: #4759 |
What version of
astro
are you using?1.1.3
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
Compiling an Astro site (live, with
astro dev
) that consumes React and SolidJS components written in TypeScript causes errors.More specifically, it throws the following 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.".
All React and SolidJS files have a
.tsx
extension, this error is misleading. It at least appears to me there is something more going on.Some more details about the setup:
jsxImportSource
is defined intsconfig.json
, assolid-js
/** @jsxImportSource react */
is used/** @jsxImportSource solid-js*/
to the SolidJS component works around the issue, but this is not expected behavior, as the jsx import source is expected to be read fromtsconfig.json
Thankfully, this behavior seems consistent and is reproducible on stackblitz, see the provided link.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-jhuzfh-anftcy?file=src/pages/index.astro
Participation
The text was updated successfully, but these errors were encountered: