【发布时间】:2018-08-24 01:17:57
【问题描述】:
当我尝试从在索引文件中导出的父文件夹中导入一个类时,我收到此错误:
TypeError: Super expression 必须为 null 或函数,而不是未定义
当我在其他地方导入时,没有问题。
导入:import { BaseComponent } from '../';
父文件夹中的索引文件:
import BaseComponent from './BaseComponent';
import Header from './Header';
import NavigationBar from './NavigationBar';
export { BaseComponent, Header, NavigationBar };
在其他文件中导入:import { BaseComponent, NavigationBar, Header } from './common';
为什么导入在子文件夹中时不起作用?
更新
文件结构:
common/
BaseComponent/
index.js
Header/
index.js
NavigationBar/
index.js (import not working for BaseComponent)
index.js (export file)
App.js (correct import)
更新 2
此导入确实有效,但我正在尝试使用索引文件来组合类:import BaseComponent from "../BaseComponent";
更新 3
【问题讨论】:
-
导入路径可能有误。请验证
-
您使用什么工具来捆绑/解析您的导入?网页包?
-
@ShubhamKhatri 我添加了项目的文件结构
-
@RaphaelSchweikert 这是一个带有 create-react-app 的默认项目
-
我添加了运行时错误
标签: node.js reactjs npm import