Next.js still imports as css even when loaded with raw-loader
Nobody has claimed this yet.
- 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://stackblitz.com/edit/stackblitz-starters-gjp1z5jm?file=app%2Fpage.tsx%3AL2
To Reproduce
- import a css file using
!!raw-loader!./foo.csssyntax. - see that the raw source is imported
Current vs. Expected behavior
Currently, the styles are also applied, as can be seen by that background. Even though I want to just load its source.
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: Ubuntu 20.04.0 LTS Thu Jul 24 2025 06:30:29 GMT+0200 (Central European Summer Time)
Available memory (MB): NaN
Available CPU cores: 8
Binaries:
Node: 20.19.1
npm: 10.8.2
Yarn: 1.22.19
pnpm: 8.15.6
Relevant Packages:
next: 15.4.2-canary.15 // Latest available version is detected (15.4.2-canary.15).
eslint-config-next: N/A
react: 19.1.0
react-dom: 19.1.0
typescript: 5.8.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
CSS
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
Also tried this with resourceQuery
webpack(config) {
config.module?.rules.push({
resourceQuery: /raw/,
type: "asset/source",
});
return config;
},
but that breaks even more. Rule.with doesn't seem to work at all in next.js. Would love to be able to leverage import attributes and do:
import foo from './foo.css' with { type: 'asset/source' }
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the linked StackBlitz reproduction and inspect the webpack(config) customization and CSS import using raw-loader syntax. Reproduce the behavior in next dev and next build, then verify that loading CSS as raw source returns only its source without applying the styles; also assess the reported resourceQuery and import-attributes approaches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css, nextjs, react, typescript, webpack
- Domain
- build-system, frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100