facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.28k stars 24.35k forks source link

Unable to resolve module after upgrade (0.44.0 TO 0.46.3) #15284

Closed jamesone closed 7 years ago

jamesone commented 7 years ago

Is this a bug report?

Yes

Environment

  1. react-native -v: 0.1.7
  2. node -v: 6.2
  3. npm -v: 5.0.3
  4. yarn --version: 0.24.6

Then, specify:

Steps to Reproduce

  1. Setup RN project
  2. Add folder in root (lets call it images)
  3. Inside that folder add a couple of image files (.png)
  4. Add a package.json file inside the images folder
  5. require('img/myimage.png')
{
  "name": "img",
  "version": "0.0.1"
}

Expected Behavior

I expect that the image (myimage.png) is required into the file WITHOUT any packager errors. Note: I am trying to import an image and display it in an <Image /> component

Actual Behavior

The packager throws an error (the simulator also shows a red screen):

error: bundling failed: "Unable to resolve module `img/map_pin_bubble_2_char@2x.png` from `/Users/james/plural/mobileapp/app/common/Marker.js`: Module does not exist in the module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n  1. Clear watchman watches: `watchman watch-del-all`.\n  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n  3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`."

Note: I followed the steps the packager suggested & still got the same issue.

Notes

I was thinking that maybe RN 0.46 phased out the usage of package.json creating import shortcuts? I couldn't confirm this anywhere though?

RyanMitchellWilson commented 7 years ago

I had similar issues trying to upgrade, removing the @2x from the imports seemed to do the trick.

jamesone commented 7 years ago

@RyanMitchellWilson Can confirm that this worked! 😄