【发布时间】:2017-04-13 21:42:43
【问题描述】:
我在尝试简化导入时遇到 webpack TypeError。以下代码可以正常工作。在这里,我从 core/components/form/index.js 导入一个名为 smartForm 的 React 高阶组件 (HOC)。
core/components/form/index.js(对smartForm进行命名导出)
export smartForm from './smart-form';
login-form.jsx(导入并使用smartForm)
import { smartForm } from 'core/components/form';
class LoginForm extends React.Component {
...
}
export default smartForm(LoginForm);
但是,我想将导入简化为 import { smartForm } from 'core'。所以我在core/index.js 中重新导出了smart-form 并从core 导入它。请看下面的代码:
core/index.js(对smartForm进行命名导出)
export { smartForm } from './components/form';
// export smartForm from './components/form'; <--- Also tried this
login-form.jsx(导入并使用smartForm)
import { smartForm } from 'core';
class LoginForm extends React.Component {
...
}
export default smartForm(LoginForm); // <--- Runtime exception here
此代码编译没有任何问题,但我在export default smartForm(LoginForm); 行收到以下运行时异常:
login-form.jsx:83 Uncaught TypeError: webpack_require.i(...) is not a function(...)
我错过了什么?
附:以下是我正在使用的 Bable 和插件版本:
"babel-core": "^6.18.2",
"babel-preset-es2015-webpack": "^6.4.3",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-1": "^6.16.0",
【问题讨论】:
标签: reactjs webpack ecmascript-6 babeljs es6-module-loader