我最近把我的webpack从版本1.12.9升级到了1.12.13,把巴别塔从5升级到了6,升级后我的部分代码中断了:
const DevTools = require('../components/DevTools.js')
DevTools.instrument()我得到了以下错误:
Uncaught TypeError: DevTools.instrument is not a function然后我在调用instrument()之前添加了console.log(DevTools),这是Chrome控制台中的输出:
> Object {__esModule: true}
> __esModule: true
> default: DevTools(props, context)
> __proto__: Object为了解决这个问题,我使用import而不是require
import DevTools from '../components/DevTools.js'再次打印console.log(DevTools)将显示以下内容:
DevTools(props, context) {
_classCallCheck(this, DevTools);
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));
if (!props.store && !…这正是我想要导入的,现在运行得很好。
有人知道为什么会这样吗?这个错误是因为升级了webpack还是巴别塔?
发布于 2016-04-07 04:08:44
您还可以通过添加default来有条件地需要它们,而不是总是导入DevTools
const DevTools = require('../components/DevTools.js').default;https://stackoverflow.com/questions/35497618
复制相似问题