React 模块不能作为依赖项正确导入到另一个模块中
React module doesn't import correctly into another as dependency
我遇到了下一个问题。
存在 lib,构建到 bundle.js,位于 npm 存储库中并包含一些逻辑
并且还存在导入此库的父应用程序(类似于元应用程序)。
现在,有一些代码:
...
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)}
但只导入了空对象(控制台、日志依赖模块 pritns 正常)。
虽然我一直在调试它,但我在
中看到了
(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
FWIW 我通过删除 React 热加载程序来修复它,包括从 .babelrc
文件、webpack.config.js
和 package.json
npm remove react-hot-loader
我遇到了下一个问题。 存在 lib,构建到 bundle.js,位于 npm 存储库中并包含一些逻辑 并且还存在导入此库的父应用程序(类似于元应用程序)。
现在,有一些代码:
...
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)}
但只导入了空对象(控制台、日志依赖模块 pritns 正常)。
虽然我一直在调试它,但我在
中看到了(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
FWIW 我通过删除 React 热加载程序来修复它,包括从 .babelrc
文件、webpack.config.js
和 package.json
npm remove react-hot-loader