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