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

Cannot find any of modules: sass,node-sass #1259

Closed
hyrious opened this issue Dec 3, 2021 · 9 comments
Closed

Cannot find any of modules: sass,node-sass #1259

hyrious opened this issue Dec 3, 2021 · 9 comments
Labels
documentation Improvements or additions to documentation question A user question

Comments

@hyrious
Copy link

hyrious commented Dec 3, 2021

Describe the bug

The same as #622, but I can not get over it.

To Reproduce

I didn't use svelte-preprocess and/or svelte.config.js. I'm using the @sveltejs/vite-plugin-svelte and let vite handle the preprocessing through useVitePreprocess option.

In fact, this plugin works well and vite does not complain about it. But vscode does not think so, it throws error on <style lang="scss"> tag about not founding "sass" or "node-sass" package.

I've created a reproduction repo: https://github.com/hyrious/vite-svelte-sass-bug.

I have tried these steps but no luck:

  • add svelte.language-server.runtime option
  • install sass both in the project and in global

Expected behavior

The extension should be able to find the sass module.

Screenshots

Snipaste_2021-12-03_14-23-39

System (please complete the following information):

  • OS: macOS 12.0.1
  • IDE: VSCode
  • Plugin/Package: Svelte for VSCode, svelte-language-server

Additional context

@hyrious hyrious added the bug Something isn't working label Dec 3, 2021
@hyrious
Copy link
Author

hyrious commented Dec 3, 2021

Update: the solution seems to be install svelte-preprocess.

@jasonlyu123 jasonlyu123 added documentation Improvements or additions to documentation question A user question and removed bug Something isn't working labels Dec 3, 2021
@dummdidumm
Copy link
Member

My guess: We try to read a svelte.config.js and read the preprocessor from that by looking up the preprocess field. If that fails or there is no config (according to your description that's the case here), we fall back to using svelte-preprocess. But that package is inside the extension folder, so if it comes across a tag where preprocessing is needed, it'll start searching for SASS (in this example) or other packages starting from the extension folder - and SASS isn't in there, so it fails.
I'm not sure what the best way forward here would be.

@jasonlyu123
Copy link
Member

Yeah. my assumption is the same. Ideally, it probably should have a svelte.config.js in this case. As we can't read the preprocess config from the vite config. Maybe vite-plugin-svelte should expose their vite preprocessor so that it could be used in the svelte.config.js. But I don't know if they want to make it a public API, it does increase the maintenance burden.

Installing svelte-preprocess would work but it's a "workaround" instead of "fix". Having to install `svelte-preprocess kind of defeats the purpose of using the preprocessor of vite. And might introduce some potential inconsistency between IDE and build.

@hyrious
Copy link
Author

hyrious commented Dec 12, 2021

IMHO, the extension does not need to use exactly the same svelte-preprocess and preprocessors. You can bundle (add them to dependency) SASS (and less, stylus, etc.) into your extension to make it work in the vite situation.

To get vite preprocessors from that plugin is not an easy work. Because it takes the vite:esbuild and vite:css plugin instance at the server runtime from the plugin context provided by vite server. You cannot do the same thing out of vite.

@dummdidumm
Copy link
Member

dummdidumm commented Dec 16, 2021

I'm very hesitant to add any other dependencies solely for preprocessor diagnostics. Right now Less and SASS seem like a good addition, but with the rise of TailwindCSS people might expect something there, too, and over time it could become too bloated, and removing already added stuff is then somewhat of a breaking change. Therefore I'd like to keep this to TypeScript-only for now. Maybe we should instead switch how we deal with these diagnostic errors?

  • Option 1: ignore errors that come from missing modules if there's no svelte.config.js
  • Option 2: same as option 1 but print a warning with more explanation instead. For svelte-check, this could be a one-time when it's first encountered to not clutter up diagnostics.

What do others think about this?

@damevin
Copy link

damevin commented Jan 20, 2022

Up please ! 👋

@Lucide
Copy link

Lucide commented Mar 8, 2022

I'm hitting a related issue as well, but I'm using svelte-preprocess with rollup, and sass-embedded. The extension complains, but the build itself succeeds, as rollup.config.js contains

import sass from "sass-embedded";
//....

svelte({
	preprocess: [
		sveltePreprocess({
			sourceMap: !production,
			scss: {
				implementation: sass
			}}),

I'm using no svelte.config.js.
Is this the same case as above or I'm missing a simpler solution?

@jasonlyu123
Copy link
Member

@Lucide That's unrelated to this issue. In your case, You need a svelte.config.js as the language server also need to know how to preprocess. And we can't read the config passed into rollup-plugin-svelte in your rollup config.

dummdidumm added a commit to dummdidumm/language-tools that referenced this issue Jul 26, 2022
…lved

sveltejs#1259
sveltejs#1479
sveltejs#1558

This may give false negatives for people who do not use Vite/forgot to create a svelte.config.js when they use rollup or webpack, but that's likely OK since we can think about these diagnostics as being opt-in: you add a preprocessor config when you want the Svelte warnings, too. Most people who have this problem also likely use TypeScript or a CSS preprocessor. When using TS, errors are caught through the TS intellisense. When using a CSS preprocessor, the only warning they'll miss is the unused CSS warning, which is apparent anyway since those styles are not visible in the browser.
dummdidumm added a commit that referenced this issue Jul 27, 2022
…lved (#1569)

#1259
#1479
#1558

This may give false negatives for people who do not use Vite/forgot to create a svelte.config.js when they use rollup or webpack, but that's likely OK since we can think about these diagnostics as being opt-in: you add a preprocessor config when you want the Svelte warnings, too. Most people who have this problem also likely use TypeScript or a CSS preprocessor. When using TS, errors are caught through the TS intellisense. When using a CSS preprocessor, the only warning they'll miss is the unused CSS warning, which is apparent anyway since those styles are not visible in the browser.
dummdidumm added a commit that referenced this issue Jul 31, 2024
Removes the need for a dependency on svelte-preprocess in svelte-language-server, since that was all we used it for.

closes:
- #1683 and #1259, because the situation no longer arises (because we no longer have svelte-preprocess inside the VS Code extension)
- #2391
dummdidumm added a commit that referenced this issue Aug 19, 2024
Removes the need for a dependency on svelte-preprocess in svelte-language-server, since that was all we used it for.

closes:
- #1683 and #1259, because the situation no longer arises (because we no longer have svelte-preprocess inside the VS Code extension)
- #2391
@dummdidumm
Copy link
Member

#2452 removes svelte-preprocess, so this situations cannot occur like that anymore, therefore closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question A user question
Projects
None yet
Development

No branches or pull requests

5 participants