TypeScript cannot resolve import './globals.css' in Next.js
Cannot 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.
Fix it fast
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.ts2Match what you see, then jump to its fix
- 1
ls 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
The 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
- 1
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.json2Fix
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 typegen3Verify
Run the type check; the error on globals.css should disappear.
npx tsc --noEmitConfirmed by nextjs.org
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*.json2Fix
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 --noEmitConfirmed by typescriptlang.org
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
Upgrading to Next.js 16: middleware becomes proxy, and the other things that break
Missing Required default.js for Parallel Route
Next.js 16 renames middleware.ts to proxy.ts and its exported function to proxy.
6 causes, each with a fixWeb apps
TypeScript cannot find the type definition file for body-parser
Cannot find type definition file for 'body-parser'.
This error comes from tsconfig, not from your code.
2 causes, each with a fixWeb 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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fix