简体   繁体   English

ESLint:在“./TopBar”中找不到 TopBarClass(导入/命名)

[英]ESLint: TopBarClass not found in './TopBar'(import/named)

I'm currently building a React app using JSX & I'm getting the following error from ESLint:我目前正在使用 JSX 构建一个 React 应用程序,并且我从 ESLint 收到以下错误:

ESLint: TopBarClass not found in './TopBar'(import/named) ESLint:在“./TopBar”中找不到 TopBarClass(导入/命名)

Here's how the file looks that's producing the error.这是产生错误的文件的外观。

import React from 'react';

import { TopBarClass } from './TopBar';

export default class Game extends React.Component {

  render() {
    const { state } = this.state;
    return (
      <div id="game-inner-container">
        { TopBarClass({ isMobileOrSmall: state.isMobileOrSmall }) }
      </div>
    );
  }

}

However inside my TopBar.js I've got the following:但是在我的TopBar.js我有以下内容:

import React from 'react';

export default class TopBarClass extends React.Component {

}

Change改变

import { TopBarClass } from './TopBar';

To

import TopBarClass from './TopBar';

You are using default export, so you should import it without { / }您正在使用默认导出,因此您应该在没有{ / }情况下导入它

Or you could change the export default to only export , then what is inside { / } should match the component's name.或者您可以将export default更改为仅export ,然后{ / }应与组件的名称匹配。

You need to use import in correct way, like as below您需要以正确的方式使用导入,如下所示

import TopBarClass  from './TopBar';

It will work fine.它会正常工作。

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

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