[英]React.createElement: type is invalid - Electron-React-Boilerplate
I'm a designer who's trying to pick up some coding so I can work on my own projects in my free time.我是一名设计师,正在尝试学习一些编码,以便我可以在空闲时间处理自己的项目。 I cloned this [electron-react-boilerplate][1] to get started and am starting with the navigation UI just to get the ball rolling.
我克隆了这个 [electron-react-boilerplate][1] 以开始使用,并从导航 UI 开始只是为了让球滚动。
Error错误
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check your code at TasksPage.tsx:5.
in TasksPage (at Routes.tsx:27)
in Suspense (at Routes.tsx:26)
in TasksPage (created by Context.Consumer)
in Route (at Routes.tsx:35)
in Switch (at Routes.tsx:34)
in App (at Routes.tsx:33)
in Routes (at Root.tsx:17)
in Router (created by ConnectedRouter)
in ConnectedRouter (created by Context.Consumer)
in ConnectedRouterWithContext (created by ConnectFunction)
in ConnectFunction (at Root.tsx:16)
in Provider (at Root.tsx:15)
in Root (created by HotExportedRoot)
in AppContainer (created by HotExportedRoot)
in HotExportedRoot
in AppContainer (at app/index.tsx:15)
On TasksPage.tsx, the 5th line is <Tasks />
, which points me to the Tasks.tsx file (shown below).在 TasksPage.tsx 上,第 5 行是
<Tasks />
,它指向 Tasks.tsx 文件(如下所示)。
Tasks.tsx (export) Tasks.tsx (导出)
import React from 'react';
import { Link } from 'react-router-dom';
import routes from '../../constants/routes.json';
export default function Tasks(): JSX.Element {
return(
<div>
<div> <h2>Test</h2></div>
</div>
);
}
TasksPage.tsx (import) TasksPage.tsx (导入)
import React from 'react';
import Tasks from '../features/tasks/Tasks';
export default function TasksPage() {
return <Tasks />;
}
Routes.tsx路由.tsx
/* eslint react/jsx-props-no-spreading: off */
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import routes from './constants/routes.json';
import App from './containers/App';
import HomePage from './containers/HomePage';
// Lazily load routes and code split with webpack
const LazyCounterPage = React.lazy(() =>
import(/* webpackChunkName: "CounterPage" */ './containers/CounterPage')
);
const CounterPage = (props: Record<string, any>) => (
<React.Suspense fallback={<h1>Loading...</h1>}>
<LazyCounterPage {...props} />
</React.Suspense>
);
// Lazily load routes and code split with webpack
const LazyTasksPage = React.lazy(() =>
import(/* webpackChunkName: "TasksPage" */ './containers/TasksPage')
);
const TasksPage = (props: Record<string, any>) => (
<React.Suspense fallback={<h1>Loading...</h1>}>
<LazyTasksPage {...props} />
</React.Suspense>
);
export default function Routes() {
return (
<App>
<Switch>
<Route path={routes.TASKS} component={TasksPage} />
<Route path={routes.COUNTER} component={CounterPage} />
<Route path={routes.HOME} component={HomePage} />
</Switch>
</App>
);
}
routes.json路由文件
{
"HOME": "/",
"COUNTER": "/counter",
"TASKS": "/tasks"
}
Extra Pages for reference额外页面供参考
HomePage.tsx主页.tsx
import React from 'react';
import Home from '../components/Home';
export default function HomePage() {
return <Home />;
}
CounterPage.tsx CounterPage.tsx
import React from 'react';
import Counter from '../features/counter/Counter';
export default function CounterPage() {
return <Counter />;
}
It could be linked to that : https://stackoverflow.com/a/48272291/9201061它可以链接到: https : //stackoverflow.com/a/48272291/9201061
Since you're using .ts and .tsx, you need to tell it to look for those too in your Webpack config using resolve.extensions:
由于您使用的是 .ts 和 .tsx,您需要告诉它使用 resolve.extensions 在您的 Webpack 配置中查找这些文件:
Edit: : Maybe you should add : JSX.Element
after TasksPage()编辑::也许你应该在 TasksPage() 之后添加
: JSX.Element
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.