Skip to content

Error: Tailwind CSS: Cannot read properties of undefined (reading 'type') #1362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ehsan18t opened this issue May 13, 2025 · 6 comments · Fixed by #1363
Closed

Error: Tailwind CSS: Cannot read properties of undefined (reading 'type') #1362

ehsan18t opened this issue May 13, 2025 · 6 comments · Fixed by #1363
Assignees

Comments

@ehsan18t
Copy link

ehsan18t commented May 13, 2025

What version of Tailwind CSS are you using?

v4.1.6

What build tool (or framework if it abstracts the build tool) are you using?

Astro 5.7.12, React 19.1.0

What version of Node.js are you using?

v22.15.0

What browser are you using?

EDGE, FireFox (not relevant to the issue)

What operating system are you using?

Windows 11 24H2 IoT LTSC (not relevant to the issue)

Reproduction URL

https://github.com/ehsan18t/tw-bug-repo

Describe your issue

I don't get any suggestions from intellisense at all. I tried so many things to fix it but didn't work at all. I get errors on output tab in vscode (attached below). After change things here and there in src/styles/global.css it goes away but suggestion still doesn't work most of the time. But again, sometimes it does. If I remove everything from @theme and everything under it, everything starts working. I checked multiple time if anything is wrong with theme but it's not (according to official docs).

Locating server…
Booting server...
Setting up server…
Listening for messages…
Searching for Tailwind CSS projects in the workspace's folders.
{"tailwind":{"version":"4.1.5","features":["css-at-theme","layer:base","content-list","source-inline","source-not"],"isDefaultVersion":false},"path":"c:/Users/Ehsan/Desktop/tw-bug-repo/src/styles/global.css"}
[Global] Creating projects: [{"folder":"C:\\Users\\Ehsan\\Desktop\\tw-bug-repo","config":"C:/Users/Ehsan/Desktop/tw-bug-repo/src/styles/global.css","selectors":[{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/src/styles/global.css","priority":0},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/.gitattributes","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/.prettierrc.mjs","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/.vscode/extensions.json","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/.vscode/launch.json","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/.vscode/settings.json","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/astro.config.mjs","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/package.json","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/public/favicon.svg","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/README.md","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/src/layouts/MainLayout.astro","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/src/pages/index.astro","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/src/pages/robots.txt.ts","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/src/styles/global.css","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/tsconfig.json","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/*","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/.vscode/**/*.{,aspx,astro,cjs,css,cts,eex,erb,gjs,gts,haml,handlebars,hbs,heex,html,jade,js,json,jsx,liquid,md,mdx,mjs,mts,mustache,njk,nunjucks,php,pug,py,razor,rb,rhtml,rs,slim,svelte,svg,tpl,ts,tsx,twig,vue}","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/src/**/*.{,aspx,astro,cjs,css,cts,eex,erb,gjs,gts,haml,handlebars,hbs,heex,html,jade,js,json,jsx,liquid,md,mdx,mjs,mts,mustache,njk,nunjucks,php,pug,py,razor,rb,rhtml,rs,slim,svelte,svg,tpl,ts,tsx,twig,vue}","priority":1},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/src/styles/**","priority":2},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/**","priority":4},{"pattern":"C:/Users/Ehsan/Desktop/tw-bug-repo/**","priority":5}],"user":false,"tailwind":{"version":"4.1.5","features":["css-at-theme","layer:base","content-list","source-inline","source-not"],"isDefaultVersion":false}}]
[Global] Preparing projects...
[Global] Initializing projects...
[src\styles\global.css] Initializing...
[Global] Adding watch patterns: C:/Users/Ehsan/Desktop/tw-bug-repo/src/styles/global.css, C:/Users/Ehsan/Desktop/tw-bug-repo/src/styles, C:/Users/Ehsan/Desktop/tw-bug-repo/src, C:/Users/Ehsan/Desktop/tw-bug-repo, C:/Users/Ehsan/Desktop, C:/Users/Ehsan, C:/Users, C:/
[src\styles\global.css] supported features: ["css-at-theme","layer:base","content-list","source-inline","source-not"]
[src\styles\global.css] Loaded tailwindcss v4.1.5: c:\Users\Ehsan\Desktop\tw-bug-repo\node_modules\tailwindcss
[src\styles\global.css] Building...
[Global] Adding watch patterns: c:\Users\Ehsan\Desktop\tw-bug-repo\node_modules\tailwindcss\index.css
[Error - 2:59:46 PM] Tailwind CSS: Cannot read properties of undefined (reading 'type')
TypeError: Cannot read properties of undefined (reading 'type')
    at Bee (c:\Users\Ehsan\.vscode\extensions\bradlc.vscode-tailwindcss-0.14.16\dist\tailwindServer.js:1775:777)
    at q8e (c:\Users\Ehsan\.vscode\extensions\bradlc.vscode-tailwindcss-0.14.16\dist\tailwindServer.js:1775:1235)
    at W8e (c:\Users\Ehsan\.vscode\extensions\bradlc.vscode-tailwindcss-0.14.16\dist\tailwindServer.js:1775:1335)
    at c:\Users\Ehsan\.vscode\extensions\bradlc.vscode-tailwindcss-0.14.16\dist\tailwindServer.js:1775:71808
    at String.replace (<anonymous>)
    at o6e (c:\Users\Ehsan\.vscode\extensions\bradlc.vscode-tailwindcss-0.14.16\dist\tailwindServer.js:1775:71747)
    at YUe (c:\Users\Ehsan\.vscode\extensions\bradlc.vscode-tailwindcss-0.14.16\dist\tailwindServer.js:1775:69177)
    at c:\Users\Ehsan\.vscode\extensions\bradlc.vscode-tailwindcss-0.14.16\dist\tailwindServer.js:1775:69614
    at Array.flatMap (<anonymous>)
    at c:\Users\Ehsan\.vscode\extensions\bradlc.vscode-tailwindcss-0.14.16\dist\tailwindServer.js:1775:69603
[Global] Initialized 1 projects


EDIT:
OK, I've just found out if I don't use rgb() inside @theme everything works. Even though using rgb() doesn't give any error on the tailwindcss side and works perfectly but intellisense doesn't work. I've added global-works.css, removing global.css file and replacing it inside src/layouts/MainLayout.astro make the intellisense works perfectly.

@RobinMalfait RobinMalfait transferred this issue from tailwindlabs/tailwindcss May 13, 2025
@thecrypticace thecrypticace self-assigned this May 13, 2025
@thecrypticace
Copy link
Contributor

This appears to be happening because we're parsing color-mix(in oklab, rgb(1rem) 100%, transparent) and that causes errors because rgb(1rem) is invalid

@thecrypticace
Copy link
Contributor

thecrypticace commented May 13, 2025

Ah okay so its caused by this line:

--color-text-base: rgb(var(--text-base));

--text-base is still in the design system (as 1rem) so as far as IntelliSense knows this is a reference to the design system when we do lookups.

I don't think Culori is supposed to throw on invalid color parsing ever but I'll wrap things so catch the error.

@ehsan18t
Copy link
Author

Ah okay so its caused by this line:

--color-text-base: rgb(var(--text-base));

--text-base is still in the design system (as 1rem) so as far as IntelliSense knows this is a reference to the design system when we do lookups.

I don't think Culori is supposed to throw on invalid color parsing ever but I'll wrap things so catch the error.

Ah, I see now. But shouldn't it get override by what the user input or at least should throw an error?

@thecrypticace
Copy link
Contributor

But shouldn't it get override by what the user input …

This is more about how we resolve colors. It has to do a recursive lookup on the design system in case someone did something like this:

@theme {
  --color-red-500: #ff0000;
  --text-color-primary: var(--color-red-500);
}

If we see text-primary then we still want to track what color swatch it is. Variables you put inside @layer and :root are just raw CSS and so IntelliSense doesn't know about them.

This definitely shouldn't cause IntelliSense to just break tho. I've got a fix for this in #1363.

@ehsan18t
Copy link
Author

But shouldn't it get override by what the user input …

This is more about how we resolve colors. It has to do a recursive lookup on the design system in case someone did something like this:

@theme {
  --color-red-500: #ff0000;
  --text-color-primary: var(--color-red-500);
}

If we see text-primary then we still want to track what color swatch it is. Variables you put inside @layer and :root are just raw CSS and so IntelliSense doesn't know about them.

This definitely shouldn't cause IntelliSense to just break tho. I've got a fix for this in #1363.

I see.
Thanks for the fast actions.

thecrypticace added a commit that referenced this issue May 13, 2025
Fixes #1362

Basically when we'd see `rgb(1rem)` and tried to parse it with Culori it
would throw an error instead of returning `undefined` as would normally
be the case. Pretty sure this isn't supposed to throw but 🤷‍♂️
@thecrypticace
Copy link
Contributor

I'm aiming to get a release out this week (maybe tomorrow or Thursday) with a bunch of fixes so this fix will be released soon. Thanks for reporting it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants