React App无法导入与Webpack打包在一起的React App

问题描述

我有一个React应用程序,我导入了另一个名为react-lex-plus的React项目。我管理两个项目。

当我构建react-lex-plus时,webpack可以捆绑我的应用程序。但是,当我将其导入到主应用程序中时,它将引发错误,提示“ require is undefined”。

有人知道为什么会这样吗?为什么要求没有定义?

我已完成以下操作:

  1. 确保react-lex-plus'webpack.config.js具有“外部”属性,其值表示为“ commonjs react”

  2. 从react-lex-plus删除react并将其链接到我的主项目中的react库。

  3. 从主项目取消链接React,并将react安装在react-lex-plus中。

下面是来自浏览器的错误消息。

ReferenceError: require is not defined
eval
./external_%22react%22?:1:18
react
/Users/xxxxxxxx/dev/react-lex-plus/build/index.js:3360
  3357 | /*! no static exports found */
  3358 | /***/ (function(module,exports) {
  3359 | 
> 3360 | eval("module.exports = require(\"react\");\n\n//# sourceURL=webpack:///external_%22react%22?");
  3361 | 
  3362 | /***/ })
  3363 | 
View compiled
__webpack_require__
/Users/xxxxxxxx/dev/react-lex-plus/build/index.js:21
  18 | /******/         };
  19 | /******/
  20 | /******/         // Execute the module function
> 21 | /******/         modules[moduleId].call(module.exports,module,module.exports,__webpack_require__);
  22 | /******/
  23 | /******/         // Flag the module as loaded
  24 | /******/         module.l = true;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)