Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mqli/e1e6576e9838d885a43a to your computer and use it in GitHub Desktop.

Select an option

Save mqli/e1e6576e9838d885a43a to your computer and use it in GitHub Desktop.
Few Line of Hack Code Make React-Native Run on Windows

#Few Line of Hack Code Make React-Native Run on Windows

While React-Native just add support of Android,yet officeally they just only support on OSX.

After a few hours of debugging, I find a simple way of let React-Native run on Windows.

Make sure all requirements were all setup following this:

Then initilize the project following this:

The react-native run-android should deploy the app into you phone or AVD

While using 'react-native start' to run the dev server you may get some error couse it runs a bash file, goto /node_modules/react-native/local-cli/run-package.js,and change it to

'use strict';

var path = require('path');
var child_process = require('child_process');

module.exports = function(newWindow) {
  if (newWindow) {
    child_process.spawnSync('open', [
      path.resolve(__dirname, '..', 'packager', 'launchPackager.command')
    ]);
  } else {
    child_process.spawn('node', [
        path.resolve(__dirname, '..', 'packager', 'packager.js'),
        '--projectRoots',
        process.cwd(),
      ], {stdio: 'inherit'});
  }
};

Skip the bash and run the nodejs script instead.

Then the problem shows, fix it, already make a pull request facebook/react-native#2787

Finally get A blank Activity,try adb logcat fetch the error log find out that, while the app load js from

ip:8081/index.android.bundle?platform=android Then get moudle load error.

Because some the moudle path be resolve as "path\\path\\package",and while the were define where "path\path\package".

Goto project\node_modules\react-native\packager\react-packager\src\DependencyResolver\index.js

function defineModuleCode({moduleName, code, deps}) {
  deps = deps.replace(/\\\\/g,'\\');
  return [
    `__d(`,
    `'${moduleName}',`,
    `${deps},`,
    'function(global, require, module, exports) {',
    `  ${code}`,
    '\n});',
  ].join('');
}

Since the moudle system were a litte bit complicate, this may not be the best solution, and neet more test before a pull request,but I think it will get you play around.

@marudy
Copy link
Copy Markdown

marudy commented Oct 22, 2016

Issue still exists and there is no run-package.js in my project .\node_modules\react-native\local-cli either.

Managed to work around it using git bash console, taking the idea from @elsassph

@NishantDesai1306
Copy link
Copy Markdown

I am trying to develop a react-native app in Windows10, I am able to run app in my Android mobile but when the activity starts in my Mobile all I see is just white screen and just as marudy said i too can't find run-package.js in specified path. Version of react-native installed in my PC is 0.35.0

@santosh07401
Copy link
Copy Markdown

Facing the same issue in Mac as NishantDesai mentioned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment