当我尝试使用样式组件运行 Nextjs 项目时,我遇到了此错误。
这是我的 .babelrc
{
"plugins": [
[
"babel-plugin-styled-components",
{
"ssr": true,
"displayName": true
}
]
],
"presets": ["next/babel", "@babel/preset-typescript"]
}
Run Code Online (Sandbox Code Playgroud)
这是我的 next.config.js:
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
styledComponents:
Boolean |
{
displayName: Boolean | undefined,
ssr: Boolean | undefined
}
}
module.exports = nextConfig
Run Code Online (Sandbox Code Playgroud)
那么这是我的错误:语法错误:“next/font”需要 SWC,尽管由于存在自定义 babel 配置而正在使用 Babel。了解更多: https: //nextjs.org/docs/messages/babel-font-loader-conflict
我尝试在 next.config.js 中使用自定义 babel 配置,但没有按预期工作。
而且,这是我的_Document:
import Document, {
Html,
Head,
Main,
NextScript,
DocumentContext
} from 'next/document'
import { ServerStyleSheet } from …
Run Code Online (Sandbox Code Playgroud)