我已经搭建了一个相当简单的React应用程序,但是我的组件无法导入到index.js中。我的index.js包含了我主要的<App />
类的定义,它可以正常工作,并且例如有这一行:
import { IntroductionPage } from './Components/IntroductionPage.js';
在 IntroductionPage.js 文件中定义了 IntroductionPage 组件,但是在 index.js 文件中却提示 IntroductionPage 未定义的错误:
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of `App`.
in App
我不确定需要做出什么改变 - 我可以从IntroductionPage.js看到console.log输出,所以它正在运行/编译。如果我将IntroductionPage组件定义移动到index.js中,一切都很顺利。不知何故,在导入/导出步骤中我失去了它。
为什么会发生这种情况?