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

CRA2 breaks lerna project #5305

Closed
sebastienva opened this issue Oct 5, 2018 · 3 comments
Closed

CRA2 breaks lerna project #5305

sebastienva opened this issue Oct 5, 2018 · 3 comments

Comments

@sebastienva
Copy link

Is this a bug report?

I hope. It works with react-script 1.x.

Did you try recovering your dependencies?

I tried on a new app

Which terms did you search for in User Guide?

Lerna, monorepo

Environment

OS: macOS High Sierra 10.13.4
Node: 8.10.0
Yarn: 1.10.1
npm: 5.6.0

Steps to Reproduce

  1. Build a monorepo with lerna
  2. Init project 'A' with cra
  3. Create a lib 'B' (no cra) and a react component ("react" is a peer-dependancy)
  4. Include a component from lib 'B' which require 'react' to project 'B'

Expected Behavior

Component from lib 'B' is loaded.

Actual Behavior

Cannot find module 'react' from 'index.js'

Reproducible Demo

https://github.com/sebastienva/cra-lerna

This project includes 2 cra apps (test-current : react-script 1, test-next: react-script 2).

Just run yarn install && yarn test.

@osdevisnot
Copy link

@sebastienva it seems this is a change in node_modules resolution for latest jest. However, the new behaviour IMO is more standards compliant.

In version 20.0.4, jest would resolve react as dependency from current project, however, in new version 23.6.0, jest tries to resolve react from closest node_modules where the dependency is required, i.e. test-lib in your case. Also, If we were to test test-lib on its own, jest resolution will fail to see correct dependency on react.

The fix for this issue can be simple as noted in this PR on your reproducion

@sebastienva
Copy link
Author

sebastienva commented Oct 6, 2018

Hi @osdevisnot,

Thanks for you comment, I add yarn test for more convenience but if you try to run the app 'test-next' this result is the same.

If I add "react' as a dev-dependency I will loose the benefits of peer-dependency and in addition I will get the same error later in production mode.

Edit : This will probably works if I publish the lib but why the behaviour should be different ?

@sebastienva
Copy link
Author

After some digging I have found the pr related to this issue : #3884

NODE_PATH=node_modules fixes the issue.

@lock lock bot locked and limited conversation to collaborators Jan 10, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants