tailwindlabs / tailwindcss-intellisense

Intelligent Tailwind CSS tooling for Visual Studio Code
2.88k stars 195 forks source link

Can't resolve virtual modules #1101

Closed vvenv closed 4 days ago

vvenv commented 5 days ago

What version of VS Code are you using?

v1.95.3

What version of Tailwind CSS IntelliSense are you using?

v0.12.15

What version of Tailwind CSS are you using?

v3.4.14

What package manager are you using?

yarn

What operating system are you using?

macOS

Tailwind config

  darkMode: 'selector',
  content: ['**/*.ijk', 'src/**/*.ts'],
  safelist: ['shiki'],

VS Code settings

  "tailwindCSS.classAttributes": ["class"],
  "tailwindCSS.files.exclude": ["**/.git/**", "**/node_modules/**"]

Reproduction URL

A public GitHub repo that includes a minimal reproduction of the bug. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private/confidential, since we want a link to a separate, isolated reproduction anyways.

Describe your issue

There is

import { searchIndex } from 'virtual:search';

in external module dok/client.

While importing this external module:

import { search } from 'dok/client';

the vscode outputs:

[Error - 6:46:48 PM] Tailwind CSS: Can't resolve 'virtual:search' in '/Users/xxx/xxx/foo-repo/packages/bar-pkg/dist'
Error: Can't resolve 'virtual:search' in '/Users/xxx/xxx/foo-repo/packages/bar-pkg/dist'
    at p (/Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:130:7155)
    at /Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:131:713
    at /Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:134:405
    at eval (eval at create (/Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:5:78), <anonymous>:15:1)
    at /Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:134:405
    at eval (eval at create (/Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:5:78), <anonymous>:27:1)
    at /Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:134:7916
    at /Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:134:405
    at eval (eval at create (/Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:5:78), <anonymous>:15:1)
    at /Users/xxx/.vscode/extensions/bradlc.vscode-tailwindcss-0.12.15/dist/tailwindServer.js:134:405
thecrypticace commented 4 days ago

IntelliSense can't load virtual modules. Those are a built-tool specific feature and would require IntelliSense to understand the build tool in use (e.g. Vite, Rollup, esbuild, bun, etc…), be able to load the build tool config, and understand the build tool's plugins.

Gonna close this as this is unlikely to change any time soon.

Aside: is there a reason you're importing a package using virtual modules in your Tailwind CSS config?

vvenv commented 3 days ago

Thanks for declaration. Because of my project depends on a file, and this file depends on a virtual module, which returns dynamic data from the dev server. I finally found that I didn't need to let intellisense parse this file because it didn't contain any CSS data. So I excluded it through the content config, and it works now. But if the virtual module returns data containing CSS, it may still be troublesome, and we may need to use safelist config to bypass the issue.