TypeScript marks className as an error on React Native components
Property 'className' does not exist on typeShort answer
React Native components have no className prop in their own types. NativeWind adds it through a type reference file. Create nativewind-env.d.ts with the reference line, keep it out of names the compiler ignores, and restart the TypeScript server. The code can run fine while the editor still shows the error.
Fix it fast
1Find out which cause you have
List the declaration files in the project root and check whether one of them contains the NativeWind type reference.
ls *.d.ts grep -rn "nativewind/types" --include="*.d.ts" . --exclude-dir=node_modules2Match what you see, then jump to its fix
- 1
No .d.ts file in the project mentions nativewind/typesThe NativeWind type reference file does not existFix - 2
A nativewind-env style file exists, yet className is still an errorThe file exists but has a name the types are not picked up fromFix - 3
The install guide you followed is for a different NativeWind major version than the one in package.jsonThe project follows a different NativeWind major versionFix
- 1
What does the error look like?
Property 'className' does not exist on type
Cause 1 of 3
The NativeWind type reference file does not exist
1Check
NativeWind documents TypeScript support as an extra step after the Metro, Babel and CSS setup, so it is easy to skip. Search the project for the reference line.
grep -rn "nativewind/types" . --include="*.d.ts" --exclude-dir=node_modules2Fix
Create nativewind-env.d.ts in the project root with the reference line below.
// nativewind-env.d.ts
/// <reference types="nativewind/types" />3Verify
Restart the TypeScript server in your editor, then run the compiler.
npx tsc --noEmitConfirmed by nativewind.dev
Cause 2 of 3
The file exists but has a name the types are not picked up from
1Check
The NativeWind install guide lists names to avoid: nativewind.d.ts, a name that matches a file or folder in the same directory (app.d.ts next to an app folder), and a name that matches a folder in node_modules (react.d.ts).
ls *.d.ts
ls -d app node_modules/react 2>/dev/null2Fix
Rename the file to nativewind-env.d.ts, keeping the same reference line inside.
mv nativewind.d.ts nativewind-env.d.ts3Verify
Restart the TypeScript server and check the file that showed the error.
npx tsc --noEmitConfirmed by nativewind.dev
Cause 3 of 3
The project follows a different NativeWind major version
1Check
The NativeWind docs keep separate installation and migration guides for v4 and the v5 release candidate. Compare the version in package.json with the guide you used.
grep -n -E '"nativewind"|"tailwindcss"' package.json2Fix
Follow the installation guide for the version you installed, including its TypeScript step, or follow the v4 to v5 migration guide when you upgrade on purpose.
npm ls nativewind tailwindcss3Verify
After the steps for your version, run the type check.
npx tsc --noEmitConfirmed by nativewind.dev
How do I stop it coming back?
- Add the TypeScript step to the project setup checklist when you install NativeWind.
- Run tsc --noEmit in CI so a missing declaration file fails the build, not only the editor.
- Never name a declaration file after a folder next to it or a package in node_modules.
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.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Mobile apps
NativeWind classes are ignored on React Navigation screens and components
Tailwind classes do not apply to navigation screens
NativeWind only styles components it can reach.
4 causes, each with a fixWeb apps
TypeScript says my component cannot be used as a JSX component
Its return type 'Promise<Element>' is not a valid JSX element.
Before TypeScript 5.1 every JSX tag had to return exactly JSX.Element, so components returning anything wider were rejected.
2 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fix