簡體   English   中英

Recoil Nexus - 元素類型無效:需要字符串(用於內置組件)或類/函數(用於復合組件)但得到 object

[英]Recoil Nexus - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got object

我開始收到錯誤:

error - Error: Element type is invalid: expected a string (for built-in components) or
               a class/function (for composite components) but got: object.
               at ReactDOMServerRenderer.render ...

在我的 NextJS 項目中添加 TypeScript 支持時。

我搜索了類似的問題,但答案主要是關於錯誤的導入/導出。 但就我而言,似乎並非如此。

在此錯誤之前我還會收到警告:

Warning: React.jsx: type is invalid -- expected a string (for built-in components) or
a class/function (for composite components) but got: object.

Check your code at _app.js:18.
    at App (webpack-internal:///./pages/_app.js:19:16)

這是我的_app.js

import "../styles/global.scss";
import "video.js/dist/video-js.css";
import { RecoilRoot } from "recoil";
import RecoilNexus from "recoil-nexus";
import { CookiesProvider } from "react-cookie";
import Head from "next/head";

export default function App({ Component, pageProps }) {

  return (
    <>
      <Head>
        <meta name="theme-color" content="#fff" />
        <meta name="viewport" content="initial-scale=1, width=device-width" />
      </Head>
      <CookiesProvider>
        <RecoilRoot>
          <RecoilNexus />
          <Component {...pageProps} />
        </RecoilRoot>
      </CookiesProvider>
    </>
  );
}

因此,由於<RecoilNexus />部分而產生了錯誤。

我嘗試評論它並且錯誤消失了。 但是,我仍然需要在我的項目中使用它。

只需將我的_app.js文件擴展名更改為_app.tsx解決問題。 我仍然不確定為什么會發生這種情況,以及這個問題是否僅在使用recoil-nexus並將 TS 添加到 NextJS 項目時才存在,或者這是在將 TS 添加到現有項目時必須做的事情。 我很高興知道更多關於這個原因的信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 錯誤:元素類型無效:預期為字符串(對於內置組件)或類/函數(對於復合組件)但得到:ReactJS 中的對象 元素類型無效:需要一個字符串(對於內置組件)或一個類/函數(對於復合組件),但得到:對象。 ReactJS 未捕獲的錯誤:元素類型無效:期望一個字符串(對於內置組件)或類/函數(對於復合組件)但得到:對象 如何修復元素類型無效:期望一個字符串(對於內置組件)或類/函數(對於復合組件)但得到:對象 錯誤:元素類型無效:應為字符串(對於內置組件)或類/函數(對於復合組件)但得到:對象 反應:元素類型無效:應為字符串(對於內置組件)或類/函數(對於復合組件)但得到:對象 錯誤:元素類型無效:應為字符串(對於內置組件)或類/函數(對於復合組件)但得到:對象 NextJS:錯誤 - 元素類型無效:需要一個字符串(對於內置組件)或一個類/函數(對於復合組件)但得到:object React-元素類型無效:需要一個字符串(對於內置組件)或一個類/函數(對於復合組件),但得到:對象 反應錯誤:元素類型無效:期望使用字符串(對於內置組件)或類/函數(對於復合組件),但得到:對象
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM