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 Metro Bundler crashing on run-android on Windows #489

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/platform-android/src/commands/runAndroid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,24 @@ function startServerInNewWindow(port, terminal, reactNativePath) {
? `set RCT_METRO_PORT=${port}`
: `export RCT_METRO_PORT=${port}`;

/**
* Quick & temporary fix for packager crashing on Windows due to using removed --projectRoot flag
* in script. So we just replace the contents of the script with the fixed version. This should be
* removed when PR #25517 on RN Repo gets approved and a new RN version is released.
*/
const launchPackagerScriptContent = `:: Copyright (c) Facebook, Inc. and its affiliates.
::
:: This source code is licensed under the MIT license found in the
:: LICENSE file in the root directory of this source tree.

@echo off
title Metro Bundler
call .packager.bat
cd ../../../
node "%~dp0..\\cli.js" start
pause
exit`;

/**
* Set up the `.packager.(env|bat)` file to ensure the packager starts on the right port.
*/
Expand Down Expand Up @@ -296,6 +314,11 @@ function startServerInNewWindow(port, terminal, reactNativePath) {
if (/^win/.test(process.platform)) {
procConfig.detached = true;
procConfig.stdio = 'ignore';
//Temporary fix for #484. See comment on line 254
fs.writeFileSync(launchPackagerScript, launchPackagerScriptContent, {
thecodrr marked this conversation as resolved.
Show resolved Hide resolved
encoding: 'utf8',
flag: 'w',
});
return spawn('cmd.exe', ['/C', launchPackagerScript], procConfig);
}
logger.error(
Expand Down