8

I have created next.js application using npx create-next-app and have not made any changes to it.

I noticed that imported .css styles are being rendered properly in Client Side Render but not on Server Side Render.

According to Next.js document imported .css should work just fine.

_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"
  }
}

CSR:

enter image description here

SSR

enter image description here

1
  • Did you use a local http server to host the SSR version? Commented Mar 31, 2021 at 1:19

2 Answers 2

6

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.

Reference

Sign up to request clarification or add additional context in comments.

5 Comments

I just did next build and next start to check the production build. Still same issue.
i have created a new next project and also did next build and next start, styles is loaded. what version are you using?
I should read the docs better but cheers for this info
Hey @sravis did you figure out a solution for this?
This works for me. Was wrecking my brain why this was not working on local
0

I could reproduce this broken css you shared by removing this line:

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

and not:

import '../styles/globals.css'

2 Comments

of course, you should leave empty styles object there.
Named import into object doesn't work :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.