繁体   English   中英

React JS 尝试导入错误:'./Pathfinder/Pathfinder' 不包含默认导出(导入为 'Pathfinder')

[英]React JS Attempted import error: './Pathfinder/Pathfinder' does not contain a default export (imported as 'Pathfinder')

我已经查看了许多不同的可能修复方法,但我不能。 当我编译 react 代码时,我收到一条错误消息,提示我需要使用默认导出,即使我是通过类导出的。 我试过只导出我调用路径查找器脚本的部分,但这是行不通的。

import React from 'react';
import './App.css';
import Pathfinder from './Pathfinder/Pathfinder';

function App() {
  return(
    <div className="App">
      <Pathfinder></Pathfinder>
    </div>
  );
}

export default App;

探路者.js

import React, {Component} from 'react';
import Node from './Node/Node';

import './Pathfinder.css';

function app(){
  return(
    <div>
      <p>

      </p>
    </div>
  );
}

这里发生了很多有问题的事情,尤其是你有一个app组件和一个App组件。 但正如您的错误所传达的那样,您没有在 Pathfinder.js 中导出app组件。 脏修复:

export default function app() {
    // ...
}

不过,至少,我会将函数重命名为Pathfinder

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM