React module doesn't import correctly into another as dependency

668 views Asked by At

i faced with the next problem. Exists lib, which build into bundle.js, lives in npm repository and contains some logic and also exists parent application (something like meta-app), which imports this lib.

Now,there is some code:

       ...
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};

it build by webpack: https://pastebin.com/0X0Ee9D6 and 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"
  ],
 ...

So, there parent app 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",

And now, usege of this:

import * as nfCalc from 'calculator';

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

But imported only empty object (console,log fron dependency module pritns ok).

While i've been debuggin it, i saw that in

(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 in undefined

1

There are 1 answers

0
Jonathan On BEST ANSWER

FWIW I fixed it by removing the react hot loader, including from the .babelrc file, webpack.config.js and package.json npm remove react-hot-loader