首页 > React中import找不到module?

React中import找不到module?

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

项目结构如图

在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.

为何找不到这个模块?


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


根据你的代码:

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

那么在 ProductInstance.js 中应该要:

export let ProductInstance = ...

所以确认下你是否导出了

【热门文章】
【热门文章】