Unable to import static file (images) when using tamagui@latest #2461
Replies: 3 comments 5 replies
-
Migrated to discussion, this is something you have to set up right and we don't have docs yet, if you want to help document and figure out a good pattern that'd be useful. |
Beta Was this translation helpful? Give feedback.
-
I resolved the issue by;
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the solution provided by @akinwale-habibullah and @KROT47 I think this can be useful for some more people. To load the image in the end I have build a AssetImage component which depending on react-native or next.js loads images properly: import React from 'react'
import { Image } from '@my/ui'
interface AssetImageProps {
icon: number | { src: string }
}
const AssetImage: React.FC<AssetImageProps> = ({ icon }) => {
if (typeof icon === 'number') {
return <Image height={100} width={100} source={icon} />
}
return <Image height={100} width={100} src={icon.src} />
}
export default AssetImage We just need to differentiate between the type number as React Native is handling local assets differently. I have tested this for .jpg .webp and .png. For SVGs it is not working on React Native, but I rather would recommend to use react-native-svg for this case. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Current Behavior
On creating a new tamagui starter app using npm create tamagui@latest, which is currently 1.92.0, and selecting the
Free - Expo + Next in a production ready monorepo
.I created an
assets
folder in the packages/app folder and drop some images there.Currently, if I import the file like this:
I get this error:
Expected Behavior
I dont expect any error. I expect to be able to use this image in an Image tag's source prop
Tamagui Version
Platform (Web, iOS, Android)
Reproduction
System Info
Beta Was this translation helpful? Give feedback.
All reactions