nextjs - 💡(How to fix) Fix TypeScript error: Cannot find module or type declarations for side-effect CSS import in App Router [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#87205Fetched 2026-04-08 02:07:35
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×2closed ×1commented ×1issue_type_added ×1

Error Message

npx create-next-app@latest css-import-ts-error --ts --app Observe the TypeScript error reported by the editor TypeScript should not report an error for side-effect CSS imports in app/layout.tsx, as this is the officially documented and recommended pattern for importing global CSS in the App Router. TypeScript reports the following error in the editor and during type checking: The application builds and runs correctly, but the TypeScript error persists unless a manual module declaration is added.

Fix Action

Fix / Workaround

A workaround is to manually add a global declaration file:

Code Example

Import the global CSS file as a side-effect:

import "./globals.css";

---

Operating System:
  Platform: linux
  Arch: x64
  Version: Fedora (Workstation)

Binaries:
  Node: 20.x
  npm: 10.x
  Yarn: 1.22.x
  pnpm: 9.x

Relevant Packages:
  next: 15.0.0-canary.148
  eslint-config-next: 15.0.0-canary.148
  react: 19.0.0-rc
  react-dom: 19.0.0-rc
  typescript: 5.6.x

Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/vercel/next.js.git

To Reproduce

Create a new Next.js project with TypeScript and App Router: npx create-next-app@latest css-import-ts-error --ts --app

Open app/layout.tsx

Import the global CSS file as a side-effect:

import "./globals.css";

Open the project in VS Code (or run next dev) Observe the TypeScript error reported by the editor

Current vs. Expected behavior

Expected behavior: TypeScript should not report an error for side-effect CSS imports in app/layout.tsx, as this is the officially documented and recommended pattern for importing global CSS in the App Router.

Current behavior: <img width="1398" height="172" alt="Image" src="https://github.com/user-attachments/assets/8dca3ba0-d47a-44e3-a506-52409d3f60a0" /> TypeScript reports the following error in the editor and during type checking:

Cannot find module or type declarations for side-effect import of './globals.css'

The application builds and runs correctly, but the TypeScript error persists unless a manual module declaration is added.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: Fedora (Workstation)

Binaries:
  Node: 20.x
  npm: 10.x
  Yarn: 1.22.x
  pnpm: 9.x

Relevant Packages:
  next: 15.0.0-canary.148
  eslint-config-next: 15.0.0-canary.148
  react: 19.0.0-rc
  react-dom: 19.0.0-rc
  typescript: 5.6.x

Next.js Config:
  output: N/A

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

TypeScript

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

next dev (local)

Additional context

This is not a runtime or build issue — the application works as expected. The issue only affects TypeScript type checking and editor diagnostics.

A workaround is to manually add a global declaration file:

// global.d.ts

declare module "*.css";

<img width="638" height="172" alt="Image" src="https://github.com/user-attachments/assets/e789b2b3-01bc-4e2b-9a7c-9ad7f02dbac4" />

However, this feels like unnecessary boilerplate for a standard App Router setup, especially since global CSS imports in app/layout.tsx are required and documented by Next.js.

The issue appears to be reproducible locally and is not deployment-specific.

extent analysis

TL;DR

Manually adding a global declaration file with declare module "*.css"; can resolve the TypeScript error for side-effect CSS imports.

Guidance

  • Verify that the issue is specific to TypeScript type checking and editor diagnostics, and that the application builds and runs correctly.
  • Consider adding a global declaration file (global.d.ts) with the necessary module declaration to resolve the error.
  • Check if there are any updates or changes in the Next.js documentation or TypeScript configuration that may address this issue.
  • If using a code editor like VS Code, ensure that the TypeScript version and configuration are up-to-date and aligned with the project settings.

Example

// global.d.ts
declare module "*.css";

This declaration file can be added to the project root to resolve the TypeScript error.

Notes

The issue appears to be related to the TypeScript configuration and module declarations, rather than a runtime or build issue. The provided workaround may be necessary until a more official solution is available.

Recommendation

Apply workaround: Add a global declaration file (global.d.ts) with declare module "*.css"; to resolve the TypeScript error, as this is a straightforward and minimal solution to address the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix TypeScript error: Cannot find module or type declarations for side-effect CSS import in App Router [1 comments, 2 participants]