Skip to content
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

Cannot find module 'React' from 'ReactNativeDefaultInjection.js' #2155

Closed
Richard-Cao opened this issue Nov 23, 2016 · 13 comments
Closed

Cannot find module 'React' from 'ReactNativeDefaultInjection.js' #2155

Richard-Cao opened this issue Nov 23, 2016 · 13 comments

Comments

@Richard-Cao
Copy link

I run jest in Travis CI, get this error:
ERROR

My package.json:

"dependencies": {
    "react": "~15.4.1",
    "react-native": "^0.38.0",
    ...
  },
  "jest": {
    "preset": "jest-react-native"
  },
  "devDependencies": {
    "babel-jest": "^17.0.2",
    "babel-preset-react-native": "^1.9.0",
    "jest": "^17.0.3",
    "jest-react-native": "^17.0.3",
    "react-test-renderer": "^15.4.1",
    ...
  }

But on my local PC is right.

How to solve?

@Richard-Cao Richard-Cao changed the title [React-Native]Cannot find module 'React' from 'ReactNativeDefaultInjection.js' Cannot find module 'React' from 'ReactNativeDefaultInjection.js' Nov 23, 2016
@Richard-Cao
Copy link
Author

Richard-Cao commented Nov 23, 2016

I guess this error occured when system OS is Linux.
Because the same project OSX ci log is right.
And my local PC is mac.

@thedgbrt
Copy link

Same issue with Travis CI since upgrading to :

"react": "~15.4.1",
"react-native": "^0.38.0"

This runs fine :

"react": "~15.3.1",
"react-native": "^0.37.0"

@gaearon
Copy link
Contributor

gaearon commented Nov 24, 2016

From what I can see React Native 0.38 asks you to use React 15.4.0 RC 4.
Have you tried using it instead of 15.4.1?

Also related: #1840.

@cosmith
Copy link

cosmith commented Nov 24, 2016

@gaearon I have the same issue. react@~15.4.1 actually resolves to React 15.0.4-rc.4 right now so this is not the issue...

@Richard-Cao
Copy link
Author

@gaearon When run react-native init, [email protected] will generate in package.json.

@donataswix
Copy link

@Richard-Cao look at this #1840 (comment) You could try react-15.4.0-rc.2 as a temporary solution.

@donataswix
Copy link

Adding "^React$": "<rootDir>/node_modules/react" to moduleNameMapper of jest-react-native/jest-preset.json also helps. Maybe it was forgotten to update for jest release.

As another (slightly better) workaround, I'm adding this to package.json:

"jest": {
    ...
    "moduleNameMapper": {
      "^React$": "<rootDir>/node_modules/react"
    }
  }

@ColCh
Copy link
Contributor

ColCh commented Nov 29, 2016

@donataswix there is another solution. I can say, "fix" :)
facebook/react#8442 (comment)

@Richard-Cao
Copy link
Author

I see

"jest": {
    "preset": "react-native"
  }

create by react-native init, but

"jest": {
    "preset": "jest-react-native"
  }

in Jest React-Native.

What we should choose?

@ColCh
Copy link
Contributor

ColCh commented Nov 29, 2016

@Richard-Cao I suppose, it depends on used react-native version

"preset": "react-native" when using RN 0.38+

@Richard-Cao
Copy link
Author

@ColCh Thx~

@cpojer
Copy link
Member

cpojer commented Nov 29, 2016

I'll update jest-react-native today to forward to react-native. I'm also updating Jest's documentation to hint that you won't need jest-react-native any longer as the default setup with 0.38 includes a working Jest configuration.

See #2182.

@cpojer cpojer closed this as completed Nov 29, 2016
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants