【问题标题】:React-intl v5 error when loading a package with react-intl v2使用 react-intl v2 加载包时出现 React-intl v5 错误
【发布时间】:2021-04-25 21:49:26
【问题描述】:

我有一个带有 react-intl v2 的 React 应用程序,我想将它迁移到 v5。在我们的node_modules 文件夹中,我们有一个包含react-intl v2 的包的依赖项。

我升级了 React 应用程序以使用react-intl v5,它工作正常(整个应用程序都用IntlProvider 包裹)。问题是何时使用此依赖包。我得到一个:

Uncaught Invariant Violation: [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.
    at invariant (webpack-internal:///./node_modules/invariant/browser.js:40:15)
    at invariantIntlContext (webpack-internal:///./node_modules/some-library/dependency-package/node_modules/react-intl/lib/index.es.js:731:52)
    at new InjectIntl(DateTimeFormat) (webpack-internal:///./node_modules/some-library/dependency-packageg/node_modules/react-intl/lib/index.es.js:813:7)

我像往常一样使用import 导入包。我正在使用webpack 进行捆绑。既然是外部包,就应该在渲染前编译,也就是说,依赖包版本低也无所谓吧?我应该只获取 HTML,而我的 React 应用程序只是呈现它。

【问题讨论】:

    标签: reactjs webpack react-intl


    【解决方案1】:

    在 webpack 中,您应该强制将 react-intl 解析为 v5

    【讨论】:

      猜你喜欢
      • 2020-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-08
      • 2020-02-15
      • 1970-01-01
      • 2018-02-16
      • 2019-12-19
      相关资源
      最近更新 更多