-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
fix: Start Metro packager from project root #24070
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
It seems like this actually breaks our iOS CI so it may not be the right fix. Could you take a look at that? |
3cf3765
to
434699d
Compare
@cpojer My bad I didn't take into account the fact that the script could be run from a different context: in RN itself vs with RN as a dependency. Should be ok now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code analysis results:
shellcheck
found some issues.
434699d
to
423fee6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@MatthieuLemoine before I can land this could you sign the Facebook CLA? It's here: http://code.facebook.com/cla. Thank you! |
@cpojer Done! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Fixes #23342. Since Metro [v0.47](https://github.com/facebook/metro/releases/tag/v0.47.0), some babel plugins such as [babel-plugin-module-resolver](https://github.com/tleunen/babel-plugin-module-resolver) or [babel-plugin-import-graphql](https://github.com/detrohutt/babel-plugin-import-graphql) fail to resolve files if the packager is started through Xcode. They receive wrong filenames from Babel such as `${projectRoot}/node_modules/react-native/src/index.js` instead of `${projectRoot}/src/index.js`. It happens because the start command of the local-cli is not executed in the projectRoot directory. In this case, the cwd will be `${projectRoot}/node_modules/react-native`. This issue doesn't occur if you start the packager yourself using `node node_modules/react-native/local-cli/cli.js start` from your project root. It comes from this [line](https://github.com/facebook/react-native/blob/b640b6faf77f7af955e64bd03ae630ce2fb09627/scripts/packager.sh#L11). This script changed the working directory to `${projectRoot}/node_modules/react-native` and started Metro from there. Starting Metro from the project root fixes this issue. [iOS] [Fixed] - Start Metro packager from project root Pull Request resolved: #24070 Differential Revision: D14563996 Pulled By: cpojer fbshipit-source-id: cdeff34610f1ebb5fb7bc82a96f4ac9eec750d16
I'm still not able to connect Metro to Sim... not sure this is actually fixed. |
@digitaldavenyc This PRs has nothing to do with connection issues to Metro. It just makes sure that the packager is started from the project root because some babel plugins only work as intended when the packager is started from the project root. |
@MatthieuLemoine is this PR in 0.59.1? You say it "Fixes #23342." but I'm still unable to build from Xcode in 0.59.1 without running stuff in the terminal. |
@darkheartfelt I think it's only available in 0.60.2+ |
Summary
Fixes #23342.
Since Metro v0.47, some babel plugins such as babel-plugin-module-resolver or babel-plugin-import-graphql fail to resolve files if the packager is started through Xcode. They receive wrong filenames from Babel such as
${projectRoot}/node_modules/react-native/src/index.js
instead of${projectRoot}/src/index.js
.It happens because the start command of the local-cli is not executed in the projectRoot directory. In this case, the cwd will be
${projectRoot}/node_modules/react-native
.This issue doesn't occur if you start the packager yourself using
node node_modules/react-native/local-cli/cli.js start
from your project root.It comes from this line. This script changed the working directory to
${projectRoot}/node_modules/react-native
and started Metro from there.Starting Metro from the project root fixes this issue.
Changelog
[iOS] [Fixed] - Start Metro packager from project root
Test Plan