vercel / vercel/next.js

CSS chunk loaded in a script tag (CSS modules)

Open
#72,480 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug Module Resolution Webpack
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/maphe/css-module-reprex

To Reproduce

The issue is visible on the prod build:

  1. visit https://css-module-reprex.vercel.app/test
  2. the console will show the error: Uncaught SyntaxError: Unexpected token '.'
  3. the dom will have css loaded as script: <script src="/_next/static/css/f2515c4387c9bb9d.css" async=""></script>

To "reproduce" locally:

  1. npx nx build css-module-reprex --prod --skip-nx-cache
  2. look into .next/static/css
  3. there should be one stylesheet instead of 2
Current vs. Expected behavior

The CSS being chunked into 2 makes the app loads the second chunk as a script for some reason, hence the client component style is broken. There should only be one stylesheet loaded (or at least the second one shouldn't be inserted as a script)

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 12
Binaries:
  Node: 20.7.0
  npm: 10.1.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.7 // An outdated version detected (latest is 15.0.3), upgrade is highly recommended!
  eslint-config-next: 14.2.16
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.6.3
Next.js Config:
  output: N/A
 ⚠ An outdated version detected (latest is 15.0.3), upgrade is highly recommended!
   Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
   Read more - https://nextjs.org/docs/messages/opening-an-issue
Which area(s) are affected? (Select all that apply)

Module Resolution, Webpack

Which stage(s) are affected? (Select all that apply)

next build (local), Vercel (Deployed)

Additional context

After investigation, I noticed that the cause of the issue is having the opengraph-image.tsx file import from the library that contains the components.

import { getLauncherColor } from '@css-module-reprex/ui';

getting rid of this line in opengraph-image.tsx fixes the build.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked css-module-reprex and run npx nx build css-module-reprex --prod --skip-nx-cache; inspect .next/static/css and the opengraph-image.tsx import from @css-module-reprex/ui. Done means the build produces the expected stylesheet loading behavior, with no CSS chunk inserted as a script or resulting console syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript, nextjs, react, webpack
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.