React模块没有正确导入到另一个依赖中

时间:2018-09-21 10:11:00

标签: node.js reactjs webpack react-hot-loader

我面临下一个问题。 存在于lib.js中的lib存在于npm存储库中,并包含一些逻辑 并且还存在父应用程序(类似于meta-app),该应用程序会导入此lib。

现在,有一些代码:

       ...
import reducer from './reducers'
    import Home from "./components/home";

    const namespace = 'home';
    const component = <Route path="/home" component={Home} />;
    console.log({reducer, namespace, component});

    export default {reducer, namespace, component};

它是通过webpack构建的:https://pastebin.com/0X0Ee9D6 和package.json:

{
  "name": "calculator",
  "version": "1.0.2",
  "description": "calculator",
  "scripts": {
    "dist": "webpack --mode=development",
    "test": "echo 'No Tests'"
  },
  "main": "dist/calculator.js",
  "files": [
    "src"
  ],
 ...

因此,有父应用程序package.json

{
  "name": "root",
  "version": "1.0.0",
  "private": true,
  "description": "framework",
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "eject": "react-scripts eject",
    "test": "echo 'No Tests'"
  },
  "main": "lib/root.js",
  "dependencies": {
    "@material-ui/core": "^1.5.1",
    "babel-core": "^6.26.3",
    "eslint": "^5.3.0",
    "history": "^4.7.2",
    "jwt-decode": "^2.2.0",
    "mini-css-extract-plugin": "^0.4.3",
    "calculator": "./../../packages/calculator",

现在,使用这个:

import * as nfCalc from 'calculator';

{console.log('olol', nfCalc)}

但仅导入空对象(控制台,log fron依赖模块优先)。

在调试的同时,我在

中看到了
(function () {
  var reactHotLoader = __webpack_require__(/*! react-hot-loader */ "../../node_modules/react-hot-loader/index.js").default;

  var leaveModule = __webpack_require__(/*! react-hot-loader */ "../../node_modules/react-hot-loader/index.js").leaveModule;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(Home, "Home", "C:\\Users\\sivanova\\WebstormProjects\\presale\\packages\\calculator\\src\\components\\home\\component.jsx");
  reactHotLoader.register(_default, "default", "C:\\Users\\sivanova\\WebstormProjects\\presale\\packages\\calculator\\src\\components\\home\\component.jsx");
  leaveModule(module);
})();

reactHotLoader未定义

1 个答案:

答案 0 :(得分:0)

FWIW我通过从(.babelrc文件,webpack.config.jspackage.json npm remove react-hot-loader移除反应热加载器中修复了它