[英]Next.js is not rendering CSS in Server Side Rendering
I have created next.js application using npx create-next-app
and have not made any changes to it.我已经使用 npx
npx create-next-app
创建了 next.js 应用程序,并且没有对其进行任何更改。
I noticed that imported.css
styles are being rendered properly in Client Side Render but not on Server Side Render.我注意到
imported.css
8CBA22E28EB17B5F5C6AE2A266AZ styles 在客户端渲染中正确渲染,但在服务器端渲染中没有正确渲染。
According to Next.js document imported.css should work just fine.根据Next.js 文件导入。css 应该可以正常工作。
_app.js _app.js
import '../styles/globals.css'
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp
package.json 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"
}
}
CSR:企业社会责任:
SSR固态继电器
If you are not in production mode, it's a normal behavior.如果您未处于生产模式,这是正常行为。
The doc stated this: 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.
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.
I could reproduce this broken css you shared by removing this line:我可以通过删除此行来重现您共享的这个损坏的 css:
// pages/index.js
import styles from '../styles/Home.module.css'
and not:并不是:
import '../styles/globals.css'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.