繁体   English   中英

Next.js 未在服务器端渲染中渲染 CSS

[英]Next.js is not rendering CSS in Server Side Rendering

我已经使用 npx npx create-next-app创建了 next.js 应用程序,并且没有对其进行任何更改。

我注意到imported.css 8CBA22E28EB17B5F5C6AE2A266AZ styles 在客户端渲染中正确渲染,但在服务器端渲染中没有正确渲染。

根据Next.js 文件导入。css 应该可以正常工作。

_app.js

import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

export default MyApp

package.json

{
  "name": "next-test",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "next": "10.0.9",
    "react": "17.0.1",
    "react-dom": "17.0.1"
  }
}

企业社会责任:

在此处输入图像描述

固态继电器

在此处输入图像描述

如果您未处于生产模式,这是正常行为。

该文档说明了这一点: if you disable JavaScript the CSS will still be loaded in the production build (next start). During development, we require JavaScript to be enabled to provide the best developer experience with Fast Refresh. if you disable JavaScript the CSS will still be loaded in the production build (next start). During development, we require JavaScript to be enabled to provide the best developer experience with Fast Refresh.

参考

我可以通过删除此行来重现您共享的这个损坏的 css:

// pages/index.js
import styles from '../styles/Home.module.css'

并不是:

import '../styles/globals.css'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM