React中import找不到module?

在项目中使用ES6的import导入React的module,

项目结构如图

clipboard.png

在index.js中导入ProductInstance.js,代码是

import { ProductInstance } from '../components/ProductInstance'

但执行Babel后浏览器没有导入进去,导致报错warning.js:44 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of Index.

为何找不到这个模块?

阅读 7.4k
2 个回答

根据你的代码:

import { ProductInstance } from '../components/ProductInstance'

那么在 ProductInstance.js 中应该要:

export let ProductInstance = ...

所以确认下你是否导出了

请把 ProductInstance.js 中的代码贴出来方便定位问题,
export default ProductInstance

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题