我刚开始使用 React Native。我连接了智能手机,在 react-native run-android
之后,我可以在屏幕上看到“Hello World”。但是,当我将“Hello World”更改为其他内容、保存文件,然后点击我设备上的重新加载命令(摇动手机后)时,我看不到任何更改。我需要再次 react-native run-android
才能看到新的东西。我在 Windows 10 上工作。构建也需要很多时间。我读过类似的东西,但没有找到任何合理的解决方案。谁能帮忙?
另外:有时,当我点击Reload
时,我需要在 packager 服务器终端中按 enter 键以重新加载 View ,但更改不会出现。
最佳答案
我遇到了同样的问题,并找到了几种解决方案。以下对我有用:
使用 >0.29 react-native-versions 启用生命重载
- go to file:
yourProjectFolder//node_modules/react-native/local-cli/server/server.js
- Commend the line (62): process.exit(11) -> //process.exit(11)
关于第 2 点:我不确定从什么时候开始 2.1 的解决方案。是需要的,但我认为 ~ react-native v.33。如果有人确切知道,请更正此问题。因为你只要看看你是否在 2 或 2.1 找到了 index.js。路径。
2.1 (Older Path of React-Native FileWatcher index.js) Go to file:
yourProjectFolder//node_modules/react-native/node_modules\node-haste\lib\FileWatcher\index.js"
2.2 (Newer Path of React-Native FileWatcher index.js) Go to file:
yourProjectFolder\node_modules\react-native\packager\react-packager\src\node-haste\FileWatcher\index.js
2.1 + 2.2 的第 1 步:
-
在
增加
:MAX_WAIT_TIME=120000
>MAX_WAIT_TIME=360000
- 将
函数 (_createWatcher)
更改为:
index.js
文件的顶部2.1 的第 2 步(index.js 的旧路径)
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);
});
});
}
2.2 的第 2 步(index.js 的新路径)
_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 - React native - 重新加载什么都不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40274012/