-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix(css): enhance error message for missing preprocessor dependency #11485
fix(css): enhance error message for missing preprocessor dependency #11485
Conversation
@@ -1504,8 +1504,10 @@ function loadPreprocessor( | |||
return (loadedPreprocessors[lang] = _require(resolved)) | |||
} catch (e) { | |||
if (e.code === 'MODULE_NOT_FOUND') { | |||
const packageManager = | |||
process.env.npm_config_user_agent?.split(' ')[0].split('/')[0] || 'npm' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that the pkgFromUserAgent
function can be reused in the same way as import { pkgFromUserAgent } from '@vite/create-vite'
or import { pkgFromUserAgent } from '@vite/shared'
, but currently, it is not exposed in that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok to duplicate it for now. It would be nice to move this into utils.ts
though, and have a separate function that returns package manager specific commands.
e.g. with yarn
and pnpm
, we want yarn add
and pnpm add
instead. That way we can do something like ${installCommand} -D ${lang}
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right... I completely forgot that yarn
does not support the i
/install
command. However, pnpm
does support pnpm i <package_name>
as an alias for pnpm add <package_name>
. Nonetheless, pnpm add
is the more officially supported method.
I will refactor it to utils.ts
and make it more verbose. Thank you for your suggestion!
Hi @bluwy Sorry for the long delay. As previously discussed, I have extracted Thank you 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Hi Vite team
Thanks for the great tool!
Description
I recently encountered an error while migrating my build tool to Vite. I had forgotten to install the preprocessor dependency. However, I really appreciate the helpful and clear TypeScript diagnostic messages that include instructions on how to fix the issue. I think these messages greatly improve DX, so I decided to add them to it.
What do you think? Thank you for your help!
Additional context
enhance error messages for missing preprocessor dependency by giving instructions like
npm i -D sass
etc.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).