无法导入react组件链接多个页面

发布于 2025-01-10 10:18:58 字数 2215 浏览 0 评论 0原文

我已经有一个简单的反应应用程序,其中有几个不同的链接页面已经有一段时间了。它已经运行了几个月,但我一定在上周做了一些事情,使我所有导出的模块都未定义。我遇到以下错误:

Error: Element 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, or you might have mixed up default and named imports.

在我的项目文件夹中,我有我的 src 文件夹,其中有我的 index.js 文件,用于配置我的所有不同模块。如下:

import { React } from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import {
  Navigation,
  Home,
  Register,
  Dashboard,
  Marketplace,
  Signup,
  Monitor,
  DSODash
} from "./Components";

ReactDOM.render(
  <Router>
    <Navigation />
    <Routes>
      <Route path="/" element={<Home />} />
      <Route path="/register" element={<Register />} />
      <Route path="/dashboard" element={<Dashboard />} />
      <Route path="/marketplace" element={<Marketplace />} />
      <Route path="/signup" element={<Signup />}/>
      <Route path="/monitor" element={<Monitor />}/>
      <Route path="/dso" element={<DSODash />}/>
    </Routes>
  </Router>,

  document.getElementById("root")
);

reportWebVitals();

在我的 src 文件夹中有一个名为 Components 的文件夹。我有几个构建单独页面的 .jsx 文件。这些文件中的每一个都被编写为函数,文件以结尾。

export default (function name);

此外,在我的 Components 文件夹中,我有一个导出每个组件的索引文件。下面是代码:

export { default as Navigation } from "./Navigation";
export { default as Home } from "./Home";
export { default as Register } from "./Register";
export { default as Dashboard } from "./Dashboard";
export { default as Marketplace } from "./Marketplace";
export { default as Signup } from "./Signup";
export { default as Monitor } from "./Monitor";
export { default as DSODash } from "./DSODash"
export { default as Base } from "./base"

似乎我的组件无法导出并导致平台出现错误。我在这里迷路了,任何帮助都会很棒。也许我需要将 src/Components 文件夹中的 index.js 文件导入到 src 文件夹中的 index.js 文件。谢谢!

I have had a simple react app with several different linked pages for quite some time now. It has been functioning for months, but I must have done something in the last week to make all of my exported modules undefined. I run into the following error:

Error: Element 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, or you might have mixed up default and named imports.

Within my project folder, I have my my src folder which has my index.js file that configures all of my different modules. Here it is below:

import { React } from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import {
  Navigation,
  Home,
  Register,
  Dashboard,
  Marketplace,
  Signup,
  Monitor,
  DSODash
} from "./Components";

ReactDOM.render(
  <Router>
    <Navigation />
    <Routes>
      <Route path="/" element={<Home />} />
      <Route path="/register" element={<Register />} />
      <Route path="/dashboard" element={<Dashboard />} />
      <Route path="/marketplace" element={<Marketplace />} />
      <Route path="/signup" element={<Signup />}/>
      <Route path="/monitor" element={<Monitor />}/>
      <Route path="/dso" element={<DSODash />}/>
    </Routes>
  </Router>,

  document.getElementById("root")
);

reportWebVitals();

Within my src folder is a folder called Components. I have several .jsx files that build individual pages. Each of these files are written as functions and the file ends with

export default (function name);

Also within my Components folder, I have an index file that exports each component. Here is the code below:

export { default as Navigation } from "./Navigation";
export { default as Home } from "./Home";
export { default as Register } from "./Register";
export { default as Dashboard } from "./Dashboard";
export { default as Marketplace } from "./Marketplace";
export { default as Signup } from "./Signup";
export { default as Monitor } from "./Monitor";
export { default as DSODash } from "./DSODash"
export { default as Base } from "./base"

It seems that somehow my components are failing to export and causes the platform to run into an error. I am lost here, and any help would be great. Maybe I need to be importing my index.js file from within the src/Components folder to the index.js file in the src folder. Thanks!

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

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

发布评论

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

评论(1

看春风乍起 2025-01-17 10:18:58

我在同一文件夹中有一个 truffle-config.js 文件。不知何故,这个配置文件一定已经干扰了反应渲染。

I had a truffle-config.js file in the same folder. Somehow this configuration file must have been interfering with the react rendering.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文