재학습/오류

[NextJS] TypeError: Cannot read properties of null (reading 'tagName')

재삉 2021. 10. 1. 04:38
반응형

오류 :

TypeError: Cannot read properties of null (reading 'tagName')

 

 

오류 발생 지점은 다음과 같다.

        <div>

            <Head>

                <meta></meta>

                <title></title>

                <link></link>

                <script></script>

                <style jsx></style>

            </Head>

        </div>

필자의 경우는 기존 HTML을 NextJS로 옮기기 위해 기존 HTML구조를 그대로 가져왔는데 ,

<style jsx></style>의 위치가 nextJS 규칙에 맞지않게 되어있었던것이 오류의 원인이였다.

왜냐하면 일반적인 HTML코드의 내부스타일은 head안에 작성되니까.

 

 

 

따라서

<style jsx>태그는 <Head>태그 바깥에 위치되어야한다.

        <div>
            <Head>
                <meta></meta>
                <title></title>
                <link></link>
                <script></script>
            </Head>
            
            <style jsx></style>
        </div>

이렇게 수정한 뒤 

TypeError: Cannot read properties of null (reading 'tagName')

에러는 해결되었다.

 

반응형