简体   繁体   English

React Native不支持在Windows上进行开发吗?

[英]React Native does not support development on Windows (yet)?

I believe masses of people are very excited about React Native now finally supporting Android too. 我相信大多数人都对React Native感到非常兴奋,现在终于支持Android了。

BUT there will be a huge disappointment that it does not support developing on Windows machines - which in many cases will prevent the uptake of React Native in bigger companies which can't just change their main OS. 但是会有一个巨大的失望,它不支持在Windows机器上进行开发 - 这在很多情况下会阻止React Native在大公司中的使用,这些公司不仅可以改变他们的主要操作系统。

I digged a bit and it seems not to hard to get it running on Windows anyway. 我挖了一下,似乎并不难让它在Windows上运行。

Change from spawn to requirejs.exec in react-native-cli index.js like this: react-native-cli index.js从spawn更改为requirejs.exec ,如下所示:

    spawn.exec(cmd + ' ' + args.join(' '), function(code, output){
      if (code !== 0) {
        cb(new Error('Command exited with a non-zero status ' + code + '\n' + cmd + ' ' + args.replace(',', ' ')));
      } else {
        cb(null);
      }
    });
    //var proc = spawn(cmd, args, {stdio: 'inherit'});
    //proc.on('close', function(code) {
    //  if (code !== 0) {
    //    cb(new Error('Command exited with a non-zero status'));
    //  } else {
    //    cb(null);
    //  }
    //});

This change enables me to run react-native run-android without any visible errors. 这个更改使我能够运行react-native run-android而没有任何可见的错误。 It starts the emulator and the app. 它启动模拟器和应用程序。

The only last missing piece to get it running on Windows is: Why does the development server not work - or why can't the app connect to it? 让它在Windows上运行的唯一最后一个缺失的部分是:为什么开发服务器无法工作 - 或为什么应用程序无法连接到它?

I get "Unable to download JS Bundle..." red screen of death. 我得到“无法下载JS Bundle ......”的死亡红屏。 It seems that react-native run-android failed to start it, even though it prints Starting JS server... . 似乎react-native run-android无法启动它,即使它打印出Starting JS server... See the complete output at the bottom. 查看底部的完整输出。

Anybody out there who can help to fix that? 有谁可以帮助解决这个问题?

Thank you 谢谢

    Y:\Mobile>react-native run-android
    Starting JS server...
        Building and installing the app on the device (cd android && gradlew.bat installDebug)...
    :app:preBuild UP-TO-DATE
    :app:preDebugBuild UP-TO-DATE
    :app:checkDebugManifest
        :app:preReleaseBuild UP-TO-DATE
    :app:prepareComAndroidSupportAppcompatV72300Library UP-TO-DATE
    :app:prepareComAndroidSupportSupportV42300Library UP-TO-DATE
    :app:prepareComFacebookFrescoDrawee061Library UP-TO-DATE
    :app:prepareComFacebookFrescoFbcore061Library UP-TO-DATE
    :app:prepareComFacebookFrescoFresco061Library UP-TO-DATE
    :app:prepareComFacebookFrescoImagepipeline061Library UP-TO-DATE
    :app:prepareComFacebookFrescoImagepipelineOkhttp061Library UP-TO-DATE
    :app:prepareComFacebookReactReactNative0110Library UP-TO-DATE
    :app:prepareOrgWebkitAndroidJscR174650Library UP-TO-DATE
    :app:prepareDebugDependencies
        :app:compileDebugAidl UP-TO-DATE
    :app:compileDebugRenderscript UP-TO-DATE
    :app:generateDebugBuildConfig UP-TO-DATE
    :app:generateDebugAssets UP-TO-DATE
    :app:mergeDebugAssets UP-TO-DATE
    :app:generateDebugResValues UP-TO-DATE
    :app:generateDebugResources UP-TO-DATE
    :app:mergeDebugResources UP-TO-DATE
    :app:processDebugManifest UP-TO-DATE
    :app:processDebugResources UP-TO-DATE
    :app:generateDebugSources UP-TO-DATE
    :app:processDebugJavaRes UP-TO-DATE
    :app:compileDebugJavaWithJavac UP-TO-DATE
    :app:compileDebugNdk UP-TO-DATE
    :app:compileDebugSources UP-TO-DATE
    :app:preDexDebug UP-TO-DATE
    :app:dexDebug UP-TO-DATE
    :app:validateDebugSigning
        :app:packageDebug UP-TO-DATE
    :app:zipalignDebug UP-TO-DATE
    :app:assembleDebug UP-TO-DATE
    :app:installDebug
    Installing APK 'app-debug.apk' on 'reactnative(AVD) - 6.0'
    Installed on 1 device.

        BUILD SUCCESSFUL

    Total time: 20.332 secs
    Starting the app (adb shell am start -n com.mobile/.MainActivity)...
    Starting: Intent { cmp=com.mobile/.MainActivity }

UPDATE UPDATE

Here are some more details of what I tried to get the development server running after I got react-native run-android working: 以下是我尝试使用react-native run-android工作后尝试运行开发服务器的更多细节:

I tried that - but `npm start' fails with: 我试过了 - 但是`npm start'失败了:

    Y:\Mobile>npm start

    > Mobile@0.0.1 start Y:\Mobile
    > node_modules/react-native/packager/packager.sh

    'node_modules' is not recognized as an internal or external command,
    operable program or batch file.

    npm ERR! Windows_NT 6.3.9600
    npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
    npm ERR! node v4.0.0
    npm ERR! npm  v2.14.2
    npm ERR! code ELIFECYCLE
    npm ERR! Mobile@0.0.1 start: `node_modules/react-native/packager/packager.sh`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the Mobile@0.0.1 start script 'node_modules/react-native/packager/packager.sh'.
    npm ERR! This is most likely a problem with the Mobile package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR!     node_modules/react-native/packager/packager.sh
    npm ERR! You can get their info via:
    npm ERR!     npm owner ls Mobile
    npm ERR! There is likely additional logging output above.

    npm ERR! Please include the following file with any support request:
    npm ERR!     Y:\Mobile\npm-debug.log

Then I tried react-native start which failed like this: 然后我尝试了react-native start ,这样react-native start失败了:

    Y:\Mobile>react-native start
    module.js:338
        throw err;
        ^

    Error: Cannot find module 'Y:\Mobile\packager.js'
        at Function.Module._resolveFilename (module.js:336:15)
        at Function.Module._load (module.js:286:25)
        at Function.Module.runMain (module.js:475:10)
        at startup (node.js:117:18)
        at node.js:951:3

Then I tried node node_modules/react-native/packager/packager.js which actually works somehow like this: 然后我尝试了node node_modules/react-native/packager/packager.js ,这实际上有点像这样工作:

    Y:\Mobile>node node_modules/react-native/packager/packager.js
     ┌────────────────────────────────────────────────────────────────────────────┐
     │  Running packager on port 8081.                                            │
     │                                                                            │
     │  Keep this packager running while developing on any JS projects. Feel      │
     │  free to close this tab and run your own packager instance if you          │
     │  prefer.                                                                   │
     │                                                                            │
     │  https://github.com/facebook/react-native                                  │
     │                                                                            │
     └────────────────────────────────────────────────────────────────────────────┘
    Looking for JS files in
       Y:\Mobile


    React packager ready.

    [10:43:07 AM] <START> Building Dependency Graph
    [10:43:07 AM] <START> Crawling File System
    [10:43:17 AM] <END>   Crawling File System (10513ms)
    [10:43:17 AM] <START> Building in-memory fs for JavaScript
    [10:43:18 AM] <END>   Building in-memory fs for JavaScript (1116ms)
    [10:43:18 AM] <START> Building in-memory fs for Assets
    [10:43:19 AM] <END>   Building in-memory fs for Assets (1090ms)
    [10:43:19 AM] <START> Building Haste Map
    [10:43:20 AM] <START> Building (deprecated) Asset Map
    [10:43:20 AM] <END>   Building (deprecated) Asset Map (221ms)
    [10:43:20 AM] <END>   Building Haste Map (639ms)
    [10:43:20 AM] <END>   Building Dependency Graph (13360ms)

But then I press Reload JS in the red screen of death and after about 30seconds or so it fails again and the development server console prints that and then exits the development server: 但后来我在死机的红屏中按下Reload JS ,大约30秒左右再次失败,开发服务器控制台打印出来然后退出开发服务器:

    <--- Last few GCs --->

      172210 ms: Scavenge 1402.5 (1455.6) -> 1402.5 (1455.6) MB, 9.6 / 0 ms (+ 2.0 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
      173083 ms: Mark-sweep 1402.5 (1455.6) -> 1402.5 (1455.6) MB, 872.5 / 0 ms (+ 3.0 ms in 2 steps since start of marking, biggest step 2.0 ms) [last resort gc].
      173954 ms: Mark-sweep 1402.5 (1455.6) -> 1402.4 (1455.6) MB, 871.1 / 0 ms [last resort gc].


    <--- JS stacktrace --->

    ==== JS stack trace =========================================

    Security context: 0000018472E37349 <JS Object>
        1: join [path.js:~217] [pc=0000039512658044] (this=0000006899C67369 <an Object with map 0000008FE2423E19>)
        2: arguments adaptor frame: 3->0
        3: /* anonymous */(aka /* anonymous */) [Y:\Mobile\node_modules\react-native\packager\react-packager\src\DependencyResolver\DependencyGraph\ResolutionRequest.js:~226] [pc=00000395137E2AFA] (this=0000018472E04131 <undefined>,realModuleN...

    FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

I think we are soooo close to get it running on Windows, I only need a bit of help with the last pieces here. 我认为我们太接近它在Windows上运行了,我只需要对这里的最后几块有点帮助。

Please help 请帮忙

UPDATE: As of version 0.14 (Oct 2015) Windows development is possible ( details ) thanks to the awesome work of the community. 更新:自版本0.14(2015年10月)以来,由于社区的出色工作,Windows开发成为可能( 细节 )。


Windows is officially not supported yet, see the documentation on Getting Started . Windows目前尚不支持,请参阅“ 入门 ”文档。

We wanted to get the release out as early as possible and focused on Mac OS first. 我们希望尽早发布,并首先关注Mac OS。

People in the community got React Native to work on Linux with some minimal changes (we'll be documenting these soon) and looks like someone just got it working on Windows too: 社区中的人们让React Native在Linux上工作并进行了一些微小的改动(我们很快就会记录这些)并且看起来有人只是让它在Windows上运行:

https://github.com/facebook/react-native/issues/2787 https://github.com/facebook/react-native/issues/2787

I found a way to fix it by installing cygwin and running: cd package sh package.sh 我通过安装cygwin并运行: cd package sh package.sh找到了解决方法

I hope it helps someone. 我希望它对某人有帮助。

ReactWindows adds support for the Windows 10 SDK, which allows you to build apps for: ReactWindows增加了对Windows 10 SDK的支持,允许您为以下内容构建应用程序:

  • Windows 10 Windows 10
  • Windows 10 Mobile Windows 10移动版
  • Xbox One (UWP) Xbox One(UWP)
  • Windows 7 and 8.1 (WPF) Windows 7和8.1(WPF)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM