且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何防止多个React副本加载?

更新时间:2023-12-01 23:11:46

由于您使用webpack,您可以为加载反应添加别名,如下所示:

Since you use webpack, you can add an alias for loading react, like this:

// In webpack.config.js

  resolve: {
    alias: {
      react: path.resolve('node_modules/react'),
    },
  },

这阻止了 addComponentAsRefTo(...)错误并使我们的构建再次成功。但是,出于某种原因,测试构建仅在我们的CI环境中失败,因为它无法解析 node_modules / react 路径。不过,我认为你不太可能遇到这个特殊问题。

This prevented the addComponentAsRefTo(...) error and made our build succeed again. However, for some reason, the testing build failed only on our CI environment as it could not resolve the node_modules/react path. I think it's unlikely that you will encounter this particular problem, though.