React Native在Windows下修改js代碼后reload無效


iOS下因為有watchman這個插件,所以啟動很快(npm start),而Windows下則非常慢,最要命的是遇到了修改js文件后,點擊reload居然一直是請求的緩存bundle,淚崩。。。

后來找到一篇文章,解決了這個問題,就是說超時導致的,但是超時的時候沒有反饋錯誤,原因不明。解決方案就是延長超時時間:

 

//\node_modules\node-haste\lib\FileWatcher\index.js
// 修改MAX_WAIT_TIME的值為360000

//找到如下代碼
key: '_createWatcher',
    value: function _createWatcher(rootConfig) {
      var watcher = new WatcherClass(rootConfig.dir, {
        glob: rootConfig.globs,
        dot: false
      });

      return new Promise(function (resolve, reject) {
        var rejectTimeout = setTimeout(function () {
          return reject(new Error(timeoutMessage(WatcherClass)));
        }, MAX_WAIT_TIME);

        watcher.once('ready', function () {
          clearTimeout(rejectTimeout);
          resolve(watcher);
        });
      });
    }
//修改為
key: '_createWatcher',
    value: function _createWatcher(rootConfig) {
      var watcher = new WatcherClass(rootConfig.dir, {
        glob: rootConfig.globs,
        dot: false
      });

      return new Promise(function (resolve, reject) {

        const rejectTimeout = setTimeout(function() {
          reject(new Error([
            'Watcher took too long to load',
            'Try running `watchman version` from your terminal',
            'https://facebook.github.io/watchman/docs/troubleshooting.html',
          ].join('\n')));
        }, MAX_WAIT_TIME);

        watcher.once('ready', function () {
          clearTimeout(rejectTimeout);
          resolve(watcher);
        });
      });
    }

參考文章:[Android][0.24.1][Windows] packager not update when change js file content #7257


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM