Skip to content
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

VSCode extension does not work when using yarn PnP #3566

Open
4 tasks done
steelywing opened this issue Feb 19, 2024 · 8 comments
Open
4 tasks done

VSCode extension does not work when using yarn PnP #3566

steelywing opened this issue Feb 19, 2024 · 8 comments

Comments

@steelywing
Copy link

steelywing commented Feb 19, 2024

UnoCSS version

0.58

Describe the bug

VSCode extension is not working when install unocss with yarn, the UnoCSS console output:

⚠️ Error on loading config. Config directory: c:\App\vite-ts\vite-project
Error: Cannot find module 'unocss'

it is normal when using npm

Reproduction

yarn create vite vite-project --template vanilla
cd vite-project
yarn add unocss

add a basic unocss config

import { defineConfig, presetAttributify, presetUno } from 'unocss';

export default defineConfig({
    presets: [
        presetUno(),
    ],
});

open the project in VSCode

System Info

No response

Validations

@steelywing steelywing changed the title VSCode extension error when using yarn VSCode extension does not work when using yarn Feb 19, 2024
@steelywing
Copy link
Author

This should relate to Yarn PNP, I see TailwindCSS extension will try to load the .pnp.js

https://github.com/tailwindlabs/tailwindcss-intellisense/blob/master/packages/tailwindcss-language-server/src/server.ts#L580

@Simon-He95
Copy link
Contributor

I have not reproduced this problem in the latest version. Please provide a more detailed reproduction demo.

@FWest98
Copy link

FWest98 commented Mar 28, 2024

The issue is with the use of Yarn PnP specifically. When using PnP, all packages are zipped and made available on demand within the runtime, so there is no node_modules folder. Consequently, the extension cannot find the unocss module.

Other plugins integrate with the concept of Editor SDKs to get the dynamic dependency loading features, but the UnoCSS extension seems to load the uno.config.ts file in the VS Code context, after which the import {..} from "unocss" line (predictably) fails.

Stacktrace from the VS Code log:

⚪️ UnoCSS for VS Code v0.58.8

📂 roots search mode.

-----------
🛠 Resolving config for /d/<path>
⚠️ Error on loading config. Config directory: /d/<path>
Error: Cannot find module 'unocss'
Require stack:
- /d/<path>/uno.config.ts
	at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
	at Function.resolve (node:internal/modules/cjs/helpers:127:19)
	at _resolve4 (/home/Floris/.vscode-server/extensions/antfu.unocss-0.58.8/dist/index.js:33588:36)
	at jiti2 (/home/Floris/.vscode-server/extensions/antfu.unocss-0.58.8/dist/index.js:33653:30)
	at /d/<path>/uno.config.ts:2:15
	at evalModule (/home/Floris/.vscode-server/extensions/antfu.unocss-0.58.8/dist/index.js:33704:15)
	at jiti2 (/home/Floris/.vscode-server/extensions/antfu.unocss-0.58.8/dist/index.js:33667:20)
	at loadConfigFile (/home/Floris/.vscode-server/extensions/antfu.unocss-0.58.8/dist/index.js:90176:13)
	at async Object.load (/home/Floris/.vscode-server/extensions/antfu.unocss-0.58.8/dist/index.js:90102:24)
	at async loadConfig (/home/Floris/.vscode-server/extensions/antfu.unocss-0.58.8/dist/index.js:90239:18)
	at async reloadConfig (/home/Floris/.vscode-server/extensions/antfu.unocss-0.58.8/dist/index.js:90291:20)
🗂️ Enabled context: [none]

@userquin
Copy link
Member

does your project empty spaces in the path? it seems you're using Windows, bad combination using spaces or accents in the path.

@FWest98
Copy link

FWest98 commented Mar 28, 2024

While, yes, the example above did have spaces in the path, the same issue with the exact same tracelog appears when running in a directory without spaces, or even when running on macOS.

@antfu antfu changed the title VSCode extension does not work when using yarn VSCode extension does not work when using yarn PnP Mar 29, 2024
@cyberalien
Copy link
Contributor

Tested, have same issue.

No special characters in path.

MacOS 14.3.1
Node 20.5.0
Yarn 3.6.0

@cyberalien
Copy link
Contributor

Actually, even vite.config.ts fails without UnoCSS:
Screenshot 2024-03-29 at 19 47 00

So this is not UnoCSS error.

@FWest98
Copy link

FWest98 commented Mar 30, 2024

This is probably caused by not using the proper PnP Editor SDK: https://yarnpkg.com/getting-started/editor-sdks. Installing this will let VS Code resolve the PnP dependencies, instead of looking in node_modules.

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

No branches or pull requests

5 participants