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