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

Production build is broken for node-haste since 15.4 #8442

Closed
ColCh opened this issue Nov 28, 2016 · 10 comments
Closed

Production build is broken for node-haste since 15.4 #8442

ColCh opened this issue Nov 28, 2016 · 10 comments
Assignees

Comments

@ColCh
Copy link

ColCh commented Nov 28, 2016

This issue is tighly coupled with issue from jest: jestjs/jest#1840
My comment for explanation, why it's related to React: jestjs/jest#1840 (comment) . I will dupe some info in current issue.

As 15.4.0-rc.2 -> 15.4.0-rc.3 version update, @providesModule React is dissapeared from production code. Under "production" I mean that code which ships with npm. And, jest tests became broken. And no way to fix it, because of version tags. Latest version with @providesModule is 15.4.0-rc.2, and it just can't be used as a workaround:

npm WARN [email protected] requires a peer of react@~15.4.0-rc.4 but none was installed.

Git tags compare ( v15.3.2...v15.4.0-rc.3 ) shows an interesting commit, 2d049e8
As we can see, that commit comes from this Pull Request: #7968

@sebmarkbage
Copy link
Collaborator

The providesModule system was never a supported way to consume React modules. The recommended way is to require('react') which should still work. Lower case CommonJS.

Is there an issue with using jest in react-native that is depending on require('React') or in your code?

@ColCh
Copy link
Author

ColCh commented Nov 28, 2016

Is there an issue with using jest in react-native that is depending on require('React') or in your code?

I personally don't use mixedcase commonjs ... only lowercase (I hase case-sensitive FS). React-native project builds successfully, so may be it's a bug somewhere in jest internally

@sebmarkbage
Copy link
Collaborator

cc @yungsters

@yungsters
Copy link
Contributor

cc @cpojer

@cpojer
Copy link
Contributor

cpojer commented Nov 29, 2016

@sebmarkbage I don't think what you are saying is true. We used haste modules from React's (and previously also fbjs) npm package in react-native-packager which is why Jest is whitelisting the package with the jest-react-native preset as well. I'm just getting back from a trip so I'm a bit unsure what happened recently but it seems to me like react-native needs to have a @providesModule React haste module proxy, no?

@sebmarkbage
Copy link
Collaborator

It does: facebook/react-native@b06b7ae

@ColCh does [email protected] help at all? just curious.

@cpojer
Copy link
Contributor

cpojer commented Nov 29, 2016

That's odd, in that case Jest definitely knows about that React module proxy. When using jest-react-native, things should just work.

@cpojer
Copy link
Contributor

cpojer commented Nov 29, 2016

Hmm, actually when we updated react-native to 15.4 we had this issue and we added an entry to the moduleNameMapper config. jest-react-native was fully merged into react-native. Simply changing your Jest config to "preset": "react-native" when using RN 0.38+, this should work.

We haven't forwarded jest-react-native to react-native yet, unfortunately. cc @kentaromiura

@ColCh
Copy link
Author

ColCh commented Nov 29, 2016

@sebmarkbage [email protected] not helps

simple grep shows that there is node-haste comment
./node_modules/react-native/Libraries/react-native/React.js: * @providesModule React

And, at same time:


    Cannot find module 'React' from 'ReactNativeMount.js'
      
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:155:17)
      at Object.<anonymous> (node_modules/react-native/Libraries/Renderer/src/renderers/native/ReactNativeMount.js:14:11)
      at Object.<anonymous> (node_modules/react-native/Libraries/Renderer/src/renderers/native/ReactNative.js:19:22)

In that file /node_modules/react-native/Libraries/Renderer/src/renderers/native/ReactNativeDefaultInjection.js we actually see this import, which can't be resolved:

var React = require('React');

@cpojer it seems that this simple change

diff --git a/package.json b/package.json
index 173950e..770acde 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
     "start": "node node_modules/react-native/local-cli/cli.js start"
   },
   "jest": {
-    "preset": "jest-react-native",
+    "preset": "react-native",
     "collectCoverageFrom": [
       "scripts/*.js",
       "src/**/*.js",

resolved require('React')

Hm... it seems it finally started to work nicely 👍 there are some diffs in snapshots, but I can handle it. Thanks!

@cpojer
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants