question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Images with @2x or @3x in their file names are not resolved (breaks static image resources)

See original GitHub issue

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

Images with @2x or @3x in the file name are not resolved when doing require('../myImage@2x.png'). If I remove the @ then it loads the file without an issue.

image

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

Others have reproduced this behavior as you can see 👉 https://github.com/facebook/react-native/issues/15030

What is the expected behavior?

I expect the files to load and be resolved without an issue. This problem breaks static image resources 👉 https://facebook.github.io/react-native/docs/images.html#static-image-resources

Please provide your exact metro-bundler configuration and mention your metro-bundler, node, yarn/npm version and operating system.

I’ve used the stock version that comes with react-native 0.47.1. I’ve also tried --reset-cache and finally I’ve also updated metro-bundler to version 0.11.0. npm 5.0.3 yarn 0.27.5 Mac OSX 10.12.6

The only workaround I’ve found is to remove the @ when requiring the file

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jeanlauliaccommented, Dec 11, 2017

Yes, a specific error message sounds good to me. I would not refer to this issue though, I’d just mention that removing the scale specifier solves the problem.

1reaction
jasperkuperuscommented, Dec 11, 2017

@jeanlauliac Is it an idea to add a better error if someone does use @2x and then refer to this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding assets and images - Flutter documentation
Flutter apps can include both code and assets (sometimes called resources). An asset is a file that is bundled and deployed with your...
Read more >
React native, Unable to resolve module for static image
In such case the path should specify the image name without the @2x or @3x suffix. For example if image file name is...
Read more >
Picture perfect images with the modern <img> element
Each image string is separated by a comma and includes: a source filename ( keyboard-400w.jpg ); a space; and the image's intrinsic width ......
Read more >
Solved: HubSpot Community - Bulk image replacement on posts
1. the file name and extension of your new files must be identical to what's in File Manager · 2. the folder name...
Read more >
A Guide to the Responsive Images Syntax in HTML - CSS-Tricks
If the browser knows it is on a higher pixel-density display (the 2x part), it will use that image instead. Demo. <img alt="A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found