错误:“无法解析模块`./InitialWindowSafeAreaInsets`

时间:2020-02-13 21:34:11

标签: reactjs react-native

我正在用React Native开发一个项目。我已经完成了编码,此后,我必须安装一些依赖项,例如react-native-screens,react-native-vector-icons等。

在我看来:“无法解析./InitialWindowSafeAreaInsets中的模块node_modules\\react-native-safe-area-context\\src\\index.tsx。下面是我的本地主机的Metro Bundler中出现的内容:


LOGGED IN AS
INFO
16:02
Starting Metro Bundler on port 19001.
INFO
16:02
Tunnel ready.
ERROR
16:03
Unable to resolve "./InitialWindowSafeAreaInsets" from "node_modules\react-native-safe-area-context\src\index.tsx"
ERROR
16:03
Building JavaScript bundle: error

我知道我可以简单地安装react-native-safe-area-context,但是由于我在GitHub和GitHub中都没有发现关于此的任何问题,我宁愿保守一点并与您分享问题,而不是安装软件包,它变成了雪球。

也许解决方案确实是安装了react-native-safe-area-context程序包,但我更喜欢以前共享,因为也许任何人都存在相同的问题,并且可能会提供更多信息。

后来,我安装了react-native-safe-area-context程序包,它仍然是相同的错误。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:13)

以下组合会发生此问题:

  • expo@3.13.1
  • react-native-safe-area-context@0.6.0

Expo要求提供react-native-safe-area-context@0.6.0,但请忽略它。 实际上,您需要@ 0.7.3。

(Expo发送“ InitialWindowSafeAreaInsets”,但@ 0.6.0无法接收。@ 0.6.0仅能接收“ InitialSafeAreaInsets”。谁移动了我的“窗口”?)

所以,请尝试这种方式。

yarn add react-native-safe-area-context@0.7.3

答案 1 :(得分:0)

对于某些人遇到的问题,必须更改Metro配置文件中的解析器才能具有 'ts'扩展名...

module.exports = {
  resolver: {
    /* resolver options */
    sourceExts: ['jsx','js','tsx', 'ts'] //add here
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
};