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
@astrojs/image overrides import type for images (including code in other frameworks like react) #5924
Comments
The value should be of shape |
This example was intentionally simplified. In a real project I use astro image in astro files, but it messes up with stuff in React files now. So if I remove those types to fix React now I will have the error in Astro |
Maybe we could make the image integration to work in Maaaybe you can create 2 tsconfigs, one targets |
Okay :) it turned out to be a bit more sinister than I thought :) it does indeed change import shape for react as well as for astro files :) I was testing my react wrong. So the issue isn't that types do not match, the issue is that image integration changes image imports for React :) |
I'm not sure if there's anything we can do here, but someone will take a look. |
if someone can test this behavior in other rendering frameworks that could be very helpful |
This is currently intended that the integration changes the shape of the ESM import in the entire project. In the future when the image integration will be merged inside core, we expect for this shape (or a similar one) to be the default Apart from documentation being unclear on this, does this cause any issue? You can do |
I'm using Astro to power an existing application (40kloc typescript/react) so it overall requires a bit more consideration than a new greenfield project :) luckily it uses typescript so it was easy to find where assets got broken, but not everyone could be as lucky, especially if those types are changing over time (like in our case, when we started using And yes, currently I'm using
I think this issue could be resolved by improvements in the documentation. I wish I had an idea for a simpler solution :) I'm a bit new to all that bunder (and loader) magic :) |
Thanks for @aFuzzyBear message in discord that fixes this issue by adding https://stackblitz.com/edit/github-xdmbqd-hbxzkd?file=src%2Fcomponents%2FCounter.tsx
I think this issue could be resolved by documenting this workaround in docs |
Closing since this is intended, we'll document this better! |
What version of
astro
are you using?1.9.2
Are you using an SSR adapter? If so, which one?
No
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
importing images in React gives typescript error because
@astrojs/image
overrides the type (but not value) fromstring
toImageMetadata
code:
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-xdmbqd?file=src/components/Counter.tsx
Participation
Update
Thanks for @aFuzzyBear message in discord that fixes this issue by adding
?url
in image importThe text was updated successfully, but these errors were encountered: