我的React Master组件找不到导入的容器

发布于 2025-01-18 14:52:52 字数 1053 浏览 2 评论 0原文

我的app.js文件无法获得另一个组件。
我正在尝试将主组合导入app.js组件,但无法获取组件。 请帮助我解决这个问题。

错误

ERROR in ./src/App.js 10:35-39
export 'Main' (imported as 'Main') was not found in './myComponents/mainComponent' (possible exports: default)

这是我的主要组件。

import React from 'react';
import ContentThree from './d53-content';

 function Main(){
  
    return (
      <div>
          < Header />
          <div className="container">
             <div className='col-12 col-md-4'></div>
             </div>
          </div>
         </Header>
      </div>
    );
}
export default Main;

这是我的app.js file **

import React, { Component } from 'react';
import { Main } from './myComponents/mainComponent';


function App(){
  
    return (
            <div>
              < Main />
            </div>
    ); 
}

export default (App);

My APP.js file cannot get another component.
I am trying to import MainComponent to the app.js component but it cannot fetch the component.
Please help me resolve this prooblem.

The error

ERROR in ./src/App.js 10:35-39
export 'Main' (imported as 'Main') was not found in './myComponents/mainComponent' (possible exports: default)

Here is my Main Component.

import React from 'react';
import ContentThree from './d53-content';

 function Main(){
  
    return (
      <div>
          < Header />
          <div className="container">
             <div className='col-12 col-md-4'></div>
             </div>
          </div>
         </Header>
      </div>
    );
}
export default Main;

Here is my app.js file*

import React, { Component } from 'react';
import { Main } from './myComponents/mainComponent';


function App(){
  
    return (
            <div>
              < Main />
            </div>
    ); 
}

export default (App);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

任性一次 2025-01-25 14:52:52

请使用

import Main from './myComponents/mainComponent';

import { Main } from './myComponents/mainComponent';

原因:您是使用导出默认main导出默认组件,这意味着它是您要导出的单个组件。因此,您需要直接导出它而不是分离它。

但是,如果您想使用import {main}'../ location_of_file',则需要像

export function Main(props){
// code
} 

一样导出它,还需要检查标题选项卡。您已经关闭了它,然后为什么要关闭它。

Please use

import Main from './myComponents/mainComponent';

instead of

import { Main } from './myComponents/mainComponent';

Reason: You are exporting the default component using export default Main which means it's a single component you are exporting. SO you need to export it directly instead of seperating it.

But still, if you want to use like import {Main} '../location_of_file' then you need to export it like

export function Main(props){
// code
} 

And also check your Header tab. You are closing it already and then why you are using to close it.

嗼ふ静 2025-01-25 14:52:52
import React from 'react';

从 './d53-content' 导入 ContentThree;

函数主(){

return (
  <div>
      < Header /> --- 1
      <div className="container">
         <div className='col-12 col-md-4'></div>
         </div>
      </div>
     </Header> -- 2
  </div>
);

}
导出默认Main;

  1. 在上面的标头组件中,第一个标签是自闭合的。
  2. 这是一个结束标签
    将第一个更改为开头标签,例如
    或删除第二个结束标签
import React from 'react';

import ContentThree from './d53-content';

function Main(){

return (
  <div>
      < Header /> --- 1
      <div className="container">
         <div className='col-12 col-md-4'></div>
         </div>
      </div>
     </Header> -- 2
  </div>
);

}
export default Main;

  1. here above in header component the first tag is self closed.
  2. and here this is a closing tag
    change the first one to just and opening tag like
    or remove the second closing tag
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文