javascript - 将 React-Navigation 与 react-native-web 一起使用会抛出错误,因为它无法导入 web 相关模块

标签 javascript react-navigation react-native-web

我正在使用带有反应导航的 react native 网络。我收到此错误:

Module not found: Can't resolve './PlatformHelpers' in '/home/vineet/projects/jm-agent-web/node_modules/react-navigation/lib'

我收到此错误是因为存在以下文件:PlatfomrHelpers.ios.js、PlatfomrHelpers.android.js、PlatfomrHelpers.web.js。但是没有 PlatfomrHelpers.js。

所以我的 ES6 导入系统无法在 react-native-web 中为导入名称“PlatfomrHelpers”导入 PlatfomrHelpers.web.js。

如何解决?

最佳答案

我想分享我实现的解决方案,它非常简单。

这个问题可以通过告诉 webpack 优先导入 .web.js 文件来解决。

我进入了我的 webpack.config.js 文件。在顶级“解析”属性中,我可以将“.web.js”添加为“扩展”数组中的一个元素。下面的代码解决了它:

extensions: ['.web.js', '.js', '.json', '.jsx']

现在我的 webpack 正在为语句选择“PlatfomrHelpers.web.js”:

import 'PlatformHelpers'

关于javascript - 将 React-Navigation 与 react-native-web 一起使用会抛出错误,因为它无法导入 web 相关模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45922573/

相关文章:

javascript - 函数不调用其他函数

javascript - 让 JEditable 处理新元素 (.live)

javascript - React Native 导航 - 绘制选项 - 添加开关

javascript - 如何从一个对象中访问 this.props?

javascript - Redis set命令成功但数据库未更改

javascript - 如何在 Typescript 中添加 Knockout 自定义函数

javascript - React Native Navigation with Redux - undefined 不是一个函数

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

javascript - 添加 react 原生矢量图标以 react 原生与 react 原生网络时出错

javascript - Expo Web 编译失败 "optional chaining"