Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

TypeScript cannot resolve import './globals.css' in Next.js

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

Short answer

TypeScript now checks imports like import './globals.css' when noUncheckedSideEffectImports is on, and it finds no type for a CSS file. Make sure next-env.d.ts exists and is listed in tsconfig include, or add a one-line declare module for css files.

  • Applies to Next.js 15, TypeScript 5.x, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look at your tsconfig.json and check two things: the include array, and whether noUncheckedSideEffectImports is set.

    grep -n "noUncheckedSideEffectImports\|\"include\"\|next-env" tsconfig.json
    ls next-env.d.ts
  2. 2Match what you see, then jump to its fix

    1. 1ls says there is no next-env.d.ts, or it is not in the include array, and CSS imports have no types.next-env.d.ts is missing or not part of tsconfig includeFix
    2. 2The option is true in tsconfig.json (or in a shared base config) and the error appears on every plain CSS import.noUncheckedSideEffectImports is on and no declaration covers CSSFix

What does the error look like?

  • Cannot find module or type declarations for side-effect import of './globals.css'.
  • ts(2882)

Cause 1 of 2

next-env.d.ts is missing or not part of tsconfig include

1Check

Next.js writes next-env.d.ts, which lets TypeScript understand stylesheet and image imports. The file must be in the include array of tsconfig.json.

cat tsconfig.json

2Fix

Add it to include and regenerate it. Next.js recreates the file whenever you run next dev, next build or next typegen. Do not edit it by hand.

// tsconfig.json
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"]

# then regenerate
npx next typegen

3Verify

Run the type check; the error on globals.css should disappear.

npx tsc --noEmit

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 2

noUncheckedSideEffectImports is on and no declaration covers CSS

1Check

By default TypeScript ignores side-effect imports it cannot resolve. With noUncheckedSideEffectImports enabled it reports them, and a bundler-handled CSS file has no source for it to find.

grep -rn "noUncheckedSideEffectImports" tsconfig*.json

2Fix

Add an ambient declaration for CSS files in a .d.ts file that tsconfig include covers.

// globals.d.ts (project root)
declare module "*.css" {}

3Verify

Run the type check again; the import now resolves.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

How do I stop it coming back?

  • Add next-env.d.ts to .gitignore and let Next.js regenerate it, as its docs advise.
  • Keep custom declarations in their own .d.ts file, not inside next-env.d.ts.
  • When you extend a shared tsconfig, check which strict flags it turns on.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.