0

When I add some image from my assets folder using require, the image is apparently being taken from a folder .png-cache , but react native probably has bad paths stored in them because I get an error wherever I've used the same file as the image source.
My code is:

 <Image
 source={require('@assets/images/thunder.svg')}
 height={20}
 width={20}
 resizeMode={'contain'}
 style={styles.actionButtonIconStyle}
 />

The image doesn't show up and the console shows:

Error: Asset not found: C:\Users\<project path>\src\assets\images\.png-cache\[email protected] for platform: android
 at getAbsoluteAssetRecord (C:\Users\<project path>\node_modules\metro\src\Assets.js:110:11)
 at async getAsset (C:\Users\<project path>\node_modules\metro\src\Assets.js:238:18)
 at async Server._processSingleAssetRequest (C:\Users\<project path>\node_modules\metro\src\Server.js:352:20)
 at async Server._processRequest (C:\Users\<project path>\node_modules\metro\src\Server.js:427:7)

Not sure why the current paths are not valid. Is it possible to make it so that the old cached paths are forgotten and new cache file generated?

What I've tried:

  • I renamed one image file and it worked but I wouldn't want to rename all the files, looking for a way to reset the cache.
  • I looked at the solution in Reset internal android image cache in React Native but I can't have dynamic paths in require so this solution didn't work.
asked Jun 30, 2022 at 17:03

2 Answers 2

2

My problem was solved by resetting the react native cache with the command:

npm start -- --reset-cache

answered Jul 4, 2022 at 9:42
Sign up to request clarification or add additional context in comments.

Comments

1

I see first time using like @asset...

In my code i everytime use like this:

<Image
 source={require('../assets/images/thunder.svg')}
 height={20}
 width={20}
 resizeMode={'contain'}
 style={styles.actionButtonIconStyle}
 />

am i missunderstanding what you need?

answered Jun 30, 2022 at 20:56

2 Comments

I have defined @assets as ./assets in my jsconfig file. And no, using it like /assets/images/thunder.svg doesn't solve the problem.
@MaheshBansod is it start with dots? (..)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.