Maaz Zindani

Loading the index…

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

TypeScript marks className as an error on React Native components

ErrorProperty 'className' does not exist on type

Short 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.

  • Applies to NativeWind 4, TypeScript 5, Expo (managed), Tailwind CSS 3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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_modules
  2. 2Match what you see, then jump to its fix

    1. 1No .d.ts file in the project mentions nativewind/typesThe NativeWind type reference file does not existFix
    2. 2A 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. 3The install guide you followed is for a different NativeWind major version than the one in package.jsonThe project follows a different NativeWind major versionFix

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_modules

2Fix

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 --noEmit

Confirmed by nativewind.dev

Did this fix it?

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/null

2Fix

Rename the file to nativewind-env.d.ts, keeping the same reference line inside.

mv nativewind.d.ts nativewind-env.d.ts

3Verify

Restart the TypeScript server and check the file that showed the error.

npx tsc --noEmit

Confirmed by nativewind.dev

Did this fix it?

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.json

2Fix

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 tailwindcss

3Verify

After the steps for your version, run the type check.

npx tsc --noEmit

Confirmed by nativewind.dev

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

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