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

fix: Start Metro packager from project root #24070

Closed
wants to merge 1 commit into from

Conversation

MatthieuLemoine
Copy link
Contributor

@MatthieuLemoine MatthieuLemoine commented Mar 20, 2019

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

@facebook-github-bot
Copy link
Contributor

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!

@pull-bot
Copy link

pull-bot commented Mar 20, 2019

Messages
📖

📋 Changelog Format - Did you include a Changelog? A changelog entry has the following format: [CATEGORY] [TYPE] - Message.

CATEGORY may be:
  • General
  • iOS
  • Android

TYPE may be:

  • Added, for new features.
  • Changed, for changes in existing functionality.
  • Deprecated, for soon-to-be removed features.
  • Removed, for now removed features.
  • Fixed, for any bug fixes.
  • Security, in case of vulnerabilities.

MESSAGE may answer "what and why" on a feature level. Use this to briefly tell React Native users about notable changes.

Generated by 🚫 dangerJS against 423fee6

@cpojer
Copy link
Contributor

cpojer commented Mar 21, 2019

It seems like this actually breaks our iOS CI so it may not be the right fix. Could you take a look at that?

@MatthieuLemoine
Copy link
Contributor Author

@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.

Copy link

@analysis-bot analysis-bot left a 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.

scripts/packager.sh Outdated Show resolved Hide resolved
@react-native-bot react-native-bot added Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. No CLA Authors need to sign the CLA before a PR can be reviewed. labels Mar 21, 2019
Copy link
Contributor

@cpojer cpojer left a comment

Choose a reason for hiding this comment

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

Nice!

@cpojer
Copy link
Contributor

cpojer commented Mar 21, 2019

@MatthieuLemoine before I can land this could you sign the Facebook CLA? It's here: http://code.facebook.com/cla.

Thank you!

@MatthieuLemoine
Copy link
Contributor Author

@cpojer Done!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 21, 2019
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

@react-native-bot react-native-bot removed the No CLA Authors need to sign the CLA before a PR can be reviewed. label Mar 21, 2019
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 21, 2019
@facebook-github-bot
Copy link
Contributor

@cpojer merged this pull request in fe3aebf.

grabbou pushed a commit that referenced this pull request Mar 22, 2019
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
@digitaldavenyc
Copy link

I'm still not able to connect Metro to Sim... not sure this is actually fixed.

@MatthieuLemoine
Copy link
Contributor Author

@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.

@running0x
Copy link

@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.

@MatthieuLemoine
Copy link
Contributor Author

@darkheartfelt I think it's only available in 0.60.2+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix packager start for XCode
8 participants