React Native Expo Web 未更新

问题描述 投票:0回答:2

我的 React Native 应用程序遇到问题: 我启动应用程序

npx expo start -w
所以它会在浏览器中打开。它通常会打开包含最新更改的应用程序。当我进行一些更改并将文件保存在应用程序/屏幕中时,应用程序将重新加载。但是当我进行更多更改并保存后,控制台会显示
web compiled successfully
但浏览器中的应用程序本身根本没有改变,即使重新加载页面/应用程序后它仍然保持原样。 有什么建议吗?问题是什么以及如何解决?

react-native expo
2个回答
9
投票

您可能有两个问题。如果您在保存文件时没有看到自动更新,可能是因为 Web 未自动启用快速刷新。我遇到了同样的问题,发现博览会的一些模板允许在网络上快速刷新,而其他模板则不允许。它让我看到那些带有 FR 的模板已安装在

expo-router 
中,并且应用程序的入口点位于
node_modules
中。
node_modules/expo-router/entry.js
指出:

expo-router

因此,如果您

// `@expo/metro-runtime` MUST be the first import to ensure Fast Refresh works // on web. import '@expo/metro-runtime'; import { App } from 'expo-router/build/qualified-entry'; import { renderRootComponent } from 'expo-router/build/renderRootComponent'; // This file should only import and register the root. No components or exports // should be added here. renderRootComponent(App);

(或者

npm install --save-dev @expo/metro-runtime
如果您使用它),然后在应用程序中入口点的最开始处导入它(它应该说明当您保存并且 Web 被捆绑时它在命令行中的位置)然后快速刷新应该可以工作。
H/t 到 github 上的 palicko 
以确认并提供步骤。 至于为什么在浏览器中硬刷新后看不到更新,这可能是另一个问题。希望你现在已经明白了!


0
投票

解决问题的步骤

安装@expo/metro-runtime 运行此命令来安装所需的包:
  1. yarn
在您的入口点导入@expo/metro-runtime
找到应用程序的入口点文件(通常为index.js、index.ts 或App.js)。在文件的最顶部添加以下行:
  1. npm install --save-dev @expo/metro-runtime
重新启动开发服务器
  1. import '@expo/metro-runtime';
	
© www.soinside.com 2019 - 2024. All rights reserved.