簡體   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