본문 바로가기
ERROR

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

by 로맨틱스터디 2023. 2. 2.
728x90
반응형

오류 메시지

Warning: React.jsx: 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 Main.js:17.
경고: React.jsx: 형식이 잘못되었습니다. 문자열(기본 제공 구성 요소) 또는 클래스/함수(복합 구성 요소)가 필요하지만, 객체를 받았습니다. 구성 요소를 정의된 파일에서 내보내는 것을 잊었거나 기본값과 명명된 가져오기를 혼합했을 수 있습니다. Main.js:17에서 코드를 확인하십시오.

 

원인

Header.js에 아무 것도 입력하지 않은 상태로 npm start 했더니 생긴 오류였다
전체적인 레이아웃 대충 잡아놓고 돌려본 거였는데, <Header> 컴포넌트만 빼먹은 거,,, 완전 똥망충이 실수

 

// Main.js

function Main() {
  return (
    <>
      <Header />
      <Outlet />
      <Footer />
    </>
  );
}

 

해결

에러가 뜬 컴포넌트 Header.js에 내용(함수 컴포넌트)을 입력하고 export하면 정상 작동한다
728x90
반응형