FrontendJun 15, 20221 min read

React 18에서 TS2339: Property 'createRoot' does not exist on type 'typeof import… 오류 해결법

React 18에서 TS2339: Property 'createRoot' does not exist on type 'typeof import… 오류 해결법에 대한 핵심 내용과 바로 적용할 포인트를 정리한 글입니다.

Author

Younggun Park

Frontend engineer and builder · Seoul, South Korea

I'm building Vision AI products at P2ACH AI, writing about frontend systems, AI tooling, and the quiet parts of shipping.

TL;DR

React 18에서 TS2339: Property 'createRoot' does not exist on type 'typeof import… 오류 해결법에 대한 핵심 내용과 바로 적용할 포인트를 정리한 글입니다.

https://velog.io/@seungmini/TypeScript에-React18-적용하기

글을 충분히 따라갔다면

index.tsx 파일의 코드는

TypeScript

import React from 'react';
import ReactDOM from "react-dom/client";
import App from './App';

const rootElement = document.getElementById('root');
if (!rootElement) throw new Error('Failed to find the root element');
const root = ReactDOM.createRoot(rootElement); // 요부분

root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

이렇게 바뀐다. 여기서 내가 마주쳤던 오류는

React 18에서 index.tsx에 TS2339 오류가 발생하는데..

TypeScript

TS2339: Property 'createRoot' does not exist on type 'typeof import…

여기서는 CreateDOM을 사용하여

TypeScript

import CreateDOM from 'react-dom/client';

...

const root = CreateDOM.createRoot(rootElement);

이렇게 바꿔주면 더이상 오류는 발생하지 않는다.

해당 문제는 @types/react-dom@^18.0.0 이상 설치하여야 해결이 가능하다.

reference

FAQ

Common follow-up questions

이 글의 핵심은 무엇인가요?
React 18에서 TS2339: Property 'createRoot' does not exist on type 'typeof import… 오류 해결법에 대한 핵심 내용과 바로 적용할 포인트를 정리한 글입니다.
실무적으로 먼저 볼 포인트는 무엇인가요?
React 18에서 TS2339: Property 'createRoot' does not exist on type 'typeof import… 오류 해결법에 대한 핵심 내용과 바로 적용할 포인트를 정리한 글입니다.

Tags

Reactfrontend

Related posts

View all writing