我正在使用带有反应导航的 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/