인프런 커뮤니티 질문&답변
Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'
작성
·
1.1K
답변 2
0
이재승
지식공유자
확인해보니 React.StrictMode 가 켜져있어서 문제가 되고있네요
StrictMode 때문에 코드가 두 번 실행되고, 첫 번째 실행에서 삭제됐는데 두 번째 실행에서 또 삭제하려다가 에러가 나는 상황입니다
React.StrictMode를 켠 상태에서는 코드를 아래처럼 변경하시면 될거에요
const bodyEl = document.getElementsByTagName("body")[0];
const loadingEl = document.getElementById("init-loading");
if (loadingEl) {
bodyEl.removeChild(loadingEl);
console.log(bodyEl, loadingEl);
}





https://drive.google.com/file/d/1PL7_VdKh_Da77Vn9PF-GYKfFDpyhMviw/view?usp=sharing