react-native - 通过expo运行react-native项目网页版的网页版时出错。消息是 - 无法编译/Libraries/StyleSheet/processColor.js

标签 react-native expo react-native-web expo-web

当我尝试通过expo运行react-native项目时,我收到此错误

E:/reacrNative23april/firestoreTester26April/node_modules/react-native/Libraries/StyleSheet/processColor.js
Module not found: Can't resolve '../Utilities/Platform' in 'E:\reacrNative23april\firestoreTester26April\node_modules\react-native\Libraries\StyleSheet'

这似乎是一个常见问题(通过谷歌搜索显而易见),但似乎尚未解决。

此链接上有一些嗡嗡声https://github.com/expo/web-examples/issues/73 ,但解决方案并不明确。

有人经历过并解决过这个问题吗?

更多数据-

  1. 我的是一个裸露的工作流程项目,带有一些 native 模块,不确定它们是否是问题
  2. 我尝试删除 node_modules 文件夹并运行 npm install,但没有成功

最佳答案

react-native 中没有非 native (即 Web)版本的实用程序/平台。

您可以创建一个 webpack.config.js ( expo has a helper for this ) 并为从各种 rn 库中使用的 Utilities/Platform 的相对引用添加一个别名到react-native-web 提供的库中:

const createExpoWebpackConfigAsync = require('@expo/webpack-config');

module.exports = async function (env, argv) {
  const config = await createExpoWebpackConfigAsync(env, argv);
  // Customize the config before returning it.
  // Resolve relative reference ../Utilities/Platform using react-native-web
  config.resolve.alias['../Utilities/Platform'] = 'react-native-web/dist/exports/Platform';
  return config;
};

关于react-native - 通过expo运行react-native项目网页版的网页版时出错。消息是 - 无法编译/Libraries/StyleSheet/processColor.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67943342/

相关文章:

javascript - 如何在我的方法中使用 React Bind ResetAction?

ios - React Native iOS 独立版在 react.ShadowQueue 上崩溃

react-native - 如何使用 React Native Stack Navigation 处理锁定方向

reactjs - 如何在 React Native 的新标签页中打开外部链接?

reactjs - 在react js和react native expo之间共享代码

React-Native/Expo Location 权限问题

javascript - (良好的编程习惯)渲染中的两个返回是否正确?

android - React-Native 使用 expo sdk 播放视频

javascript - React Native 在 Snack.expo.io 上使用本地字体

react-native - 专注于react-native-web(expo)时更改TextInput的边框颜色