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 packager start for XCode #23342

Closed
xstable opened this issue Feb 8, 2019 · 9 comments
Closed

fix packager start for XCode #23342

xstable opened this issue Feb 8, 2019 · 9 comments
Labels
Bug Platform: iOS iOS applications. Priority: Mid Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. Tool: Xcode

Comments

@xstable
Copy link

xstable commented Feb 8, 2019

Running App from XCode didn't work anymore. All paths which bable resolver plugin use are broken.
Running App from CLI with react-native start ios --reset-cache works.

Reason: packager.js will be started from wrong path.
Detail-Description & Solution

Environment

React Native Environment Info:
System:
OS: macOS 10.14.2
CPU: (4) x64 Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
Memory: 62.86 MB / 6.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.6.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.5.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
IDEs:
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.6.3 => 16.6.3
react-native: ^0.58.4 => 0.58.4
npmGlobalPackages:
react-native-cli: 2.0.1

Thanks to @emusgrave for figuring this out.

@react-native-bot react-native-bot added the Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. label Feb 8, 2019
@react-native-bot
Copy link
Collaborator

It looks like you are using an older version of React Native. Please update to the latest release, v0.58 and verify if the issue still exists.

The "Resolution: Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

@xstable
Copy link
Author

xstable commented Feb 8, 2019

I've upgraded now, issue still exists.

@MatthieuLemoine
Copy link
Contributor

This issue occurs since Metro v0.47.

It happens when the the start command of the local-cli is not executed in the projectRoot directory e.g when you let Xcode start the packager for you. In this case, the cwd will be ${projectRoot}/node_modules/react-native.

Some babel plugins such as babel-plugin-module-resolver or babel-plugin-import-graphql fail to resolve files because of it. They receive wrong filenames from Babel such as ${projectRoot}/node_modules/react-native/src/index.js instead of ${projectRoot}/src/index.js.

This issue doesn't occur if you start the packager yourself using node node_modules/react-native/local-cli/cli.js start from your projectRoot.

It comes from this line. This script change the working directory to ${projectRoot}/node_modules/react-native and start Metro from there. I think that it should cd into the projectRoot instead.

@xstable
Copy link
Author

xstable commented Mar 6, 2019

Will this be fixed in 0.59.0 ?

@michalchudziak
Copy link
Contributor

For anyone who'll pick it up, please check out #21480 - they might be connected.

@cpojer
Copy link
Contributor

cpojer commented Mar 20, 2019

Please see the workaround from @MatthieuLemoine. It seems like you have a custom setup and you need to start Metro in the right place.

@cpojer cpojer closed this as completed Mar 20, 2019
@xstable
Copy link
Author

xstable commented Mar 20, 2019

@cpojer Worked like a charm on 0.56. All the time started RN from XCode.
Don't have upgraded XCode, but only RN to 0.58.4 ... after this, the issue appears.
No special custom setup or other changes are made for the project between working version (0.56) and non-working version (0.58)

Please re-open.

@MatthieuLemoine
Copy link
Contributor

@cpojer This issue happens when you let Xcode (therefore RN build scripts) start the packager for you whatever your setup is.

The build script packager.sh should start Metro from $PROJET_DIR instead of $PROJECT_DIR/node_modules/react-native to fix this issue.

@cpojer
Copy link
Contributor

cpojer commented Mar 20, 2019

Got it. I'm gonna reopen this issue. Do you mind sending a Pull Request with the fix?

@cpojer cpojer reopened this Mar 20, 2019
grabbou pushed a commit that referenced this issue 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
@facebook facebook locked as resolved and limited conversation to collaborators Mar 21, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: iOS iOS applications. Priority: Mid Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. Tool: Xcode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants