【发布时间】:2023-01-08 13:43:41
【问题描述】:
从昨天开始,我试图解决我在 nextjs-typescript 应用程序中部署 vercel 时遇到的这个问题。但无法解决。这个错误是突然发生的,而且不是我这边的。任何的想法?
./pages/_app.tsx:76:14
Type error: 'Component' cannot be used as a JSX component.
Its element type 'ReactElement<any, any> | Component<{}, any, any> | null' is not a valid JSX element.
Type 'Component<{}, any, any>' is not assignable to type 'Element | ElementClass | null'.
Type 'Component<{}, any, any>' is not assignable to type 'ElementClass'.
The types returned by 'render()' are incompatible between these types.
Type 'React.ReactNode' is not assignable to type 'import("/vercel/path0/node_modules/@types/react-dom/node_modules/@types/react/index").ReactNode'.
Type '{}' is not assignable to type 'ReactNode'.
74 | headersData={headerData}
75 | />
> 76 | <Component {...pageProps} />
| ^
77 | <Footer />
78 | </main>
79 | </Provider>
error Command failed with exit code 1.
【问题讨论】:
-
在 package.json 文件中添加解决方案和覆盖解决了我的问题。
"resolutions": { "@types/react": "^17.0.1", "@types/react-dom": "^17.0.2" }, "overrides": { "@types/react": "^17.0.1", "@types/react-dom": "^17.0.2" } -
也为我工作
-
@Scarass 我确实在一定程度上弄明白了。我的工作区中有一个模块指向 17.0.38。我把那个下移到 17.02。我也使用了覆盖。我使用了
yarn cache clean。我擦除了我所有的 node_modules、.next、.turbo 目录。我什至可能不得不在某一时刻重新克隆该项目。最终我让它工作了。引擎盖下某处深处有一些困惑的龙......从未得到完美的答案。 -
谢谢@CodeManiak。我刚刚通过更新@types/react 和@types/react-dom 使我的工作正常。我不必使用决议和覆盖。
标签: typescript next.js