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

Resolve and load dependent module paths in react-scripts #530

Merged
merged 2 commits into from
Dec 29, 2021

Conversation

Yama-Tomo
Copy link
Contributor

issue #457, #388

Depending on the project, the installation location of the package on which react-scripts depends may change.
This fix resolves and loads the dependency paths of react-scripts.

@liby
Copy link

liby commented Aug 5, 2021

Will this PR solve the issue mentioned in this reply?

@Yama-Tomo
Copy link
Contributor Author

Probably it will work. You can try it on my forked branch.

@timarney
Copy link
Owner

If @dawnmist or others can confirm this is needed --- happy to merge.

I haven't used Create React App or react-app-rewired for a number of years now so relying on others to let me know if this breaks or maintains things.

@dawnmist
Copy link
Collaborator

Does anyone have an example mini-repo that triggers the issue that I can use for testing the fix against? I can create a "normal" example, but not having used yarn workspaces it'll take me longer to try to put something together to test that the bug is actually fixed.

const babelJest = require('babel-jest');
const { dependRequire, dependRequireResolve } = require('./dependRequire');

const babelJest = dependRequire('babel-jest');
Copy link
Collaborator

@dawnmist dawnmist Dec 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To apply against current master, line 3 needs to be edited to be:

const babelJestMd = dependRequire('babel-jest');
const babelJest = babelJestMd.__esModule ? babelJestMd.default : babelJestMd;

This is so that react-app-rewired can use either babel-jest 26 or 27+, since there was a change to using esModules in babel-jest 27.

@dawnmist
Copy link
Collaborator

I've tested it with the repository at https://github.com/NiGhTTraX/react-app-rewired-bug-457 and can confirm that it works for the cross-spawn issue.

I think it may also work for the babel-jest hoisting issue mentioned in #589 - but the example repo above works in jest with the current master version of babelTransform (i.e. without the dependRequire/dependRequireResolve changes in babelTransform), so I can't be sure on that yet. The conflict that git is reporting is for line 3 in babelTransform.js, was altered to do the esModule vs default export testing in master, so it just needs the patch to be updated to apply against the current master as per the example I provided above.

@Yama-Tomo
Copy link
Contributor Author

@dawnmist After fixing the conflicts, I applied my code to https://github.com/NiGhTTraX/react-app-rewired-bug-457 and confirmed that it works.

@dawnmist
Copy link
Collaborator

@Yama-Tomo Thank you for the rapid update!

@timarney - I can confirm that the changes work for both a new project with react-scripts 5, and on an older one with react-scripts 3, in addition to an example repo that was having issues finding the react-dev-utils/cross-spawn, so I'm happy for the changes to be merged.

@dawnmist
Copy link
Collaborator

Confirmed that the changes in this pull request also fix finding babel-jest when it is installed to node_modules/react-scripts/node_modules directory (due to hoisting or other packages having a conflicting version for babel-jest). See example repo https://github.com/Semigradsky/react-app-rewired-test.git for babel-jest testing.

@timarney timarney merged commit 6c7514e into timarney:master Dec 29, 2021
@timarney
Copy link
Owner

timarney commented Dec 29, 2021

Thanks All
Published 2.1.10

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

Successfully merging this pull request may close these issues.

None yet

4 participants