최근에 과제를 진행하며 css in js 만을 이용해서 직접 스타일링을 하다 emotion을 선택했는데,
document에 나와있는 install 절차를 진행했음에도 콘솔창에
You have tried to stringify object returned fromcssfunction. It isn't supposed to be used directly (e.g. as value of theclassNameprop), but rather handed to emotion so it can handle it (e.g. as value ofcssprop).
에러와 함께 div css="\[object Object\]"></div>
와 같이 렌더링이 되었다.
Babel 문서에는 아래와 같이 설정하면 해결할 수 있다. 매 파일마다 설정하고 싶다면 아래처럼 하면 되고
/** @jsxImportSource @emotion/react */
import { jsx, css } from '@emotion/react'
이 아래에는 전체 프로젝트에 적용하는 방법이다. Next.js에서는 아래와 같이 바벨을 설정하면 해결된다.
{
"presets": [
[
"next/babel",
{
"preset-react": {
"runtime": "automatic",
"importSource": "@emotion/react"
}
}
]
],
"plugins": ["@emotion/babel-plugin"]
}
Next.js가 아니고 .babelrc를 수정한다면, 아래와 같이 설정하면 된다.
{
"presets": [
["@babel/preset-react", { "runtime": "automatic", "importSource": "@emotion/react" }]
],
"plugins": ["@emotion/babel-plugin"]
}
'software engineering > issue' 카테고리의 다른 글
Vercel 도메인이 갑자기 안들어가지는 이슈 (0) | 2024.05.11 |
---|---|
GraphQL Apollo Error: Dynamic server usage: Page couldn't be rendered statically because it used headers (1) | 2024.01.10 |
Failed to execute 'define' on 'CustomElementRegistry' (0) | 2023.08.05 |
Next Image 외부 도메인 설정 (0) | 2023.02.04 |
Install storybook in a pnpm + nextjs workspace (0) | 2022.10.12 |