language-tools: Style tag `lang` attribute triggers warning from Svelte Beta
Describe the bug
When specifying a lang
attribute in component’s <style>
tag, Svelte Beta for VS Code gives the following warning:
The file cannot be parsed because script or style require a preprocessor that doesn't seem to be setup. Did you setup a `svelte.config.js`? See https://github.com/sveltejs/language-tools/tree/master/packages/svelte-vscode#using-with-preprocessors for more info.
This only happens when specifying the lang
attribute on the component <style>
. When the lang attribute is removed from the <style>
tag, the warning goes away, regardless of if there is a lang
attribute on the component <script>
tag.
To Reproduce Steps to reproduce the behavior:
- Create a new Svelte + Webpack project by using:
degit svelte/template-webpack
- Install TypeScript, Node Sass, and Svelte Preprocess:
npm i -D typescript node-sass svelte-preprocess
- Create a svelte.config.js:
const sveltePreprocess = require('svelte-preprocess')
module.exports = {
preprocess: sveltePreprocess()
}
- Restart Svelte Beta in VS Code
- Add
lang="scss"
to<style>
tag insrc/App.svelte
- Save file. Svelte Beta warning should appear on
<script>
tag
Expected behavior Expected Svelte Beta to not return any warnings or errors.
Screenshots
System:
- OS: Windows 10
- IDE: VSCode 1.45.0
- Plugin/Package: “Svelte Beta”
Additional context Frequently recommended/obvious fixes that did not work:
- Double, triple, and quadruple checked that I had a
svelte.config.js
file at the root of my project. - Tried setting runtime to path to Node.js:
C:\Program Files\nodejs\node.exe
- Tried the following variants of svelte.config.js:
const sveltePreprocess = require('svelte-preprocess')
module.exports = {
preprocess: [sveltePreprocess()]
}
const sveltePreprocess = require('svelte-preprocess')
module.exports = {
preprocess: sveltePreprocess({
sass: true
})
}
const sveltePreprocess = require('svelte-preprocess')
module.exports = {
preprocess: sveltePreprocess({
sass: true,
typescript: true
})
}
- Webpack configuration uses preprocess options exported by
svelte.config.js
and compiles Svelte code with no errors or warnings.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 30 (12 by maintainers)
Commits related to this issue
- more logging, better preprocessing error message Part of #86, #129, #148 — committed to dummdidumm/language-tools by deleted user 4 years ago
- more logging, better preprocessing error message (#150) * more logging, better preprocessing error message Part of #86, #129, #148 * log error during config load — committed to sveltejs/language-tools by dummdidumm 4 years ago
- (feat) better error diagnostics Narrow down in which step the error occurs and try to extract better error messages. #86, #232, #129 — committed to dummdidumm/language-tools by deleted user 4 years ago
- (feat) better error diagnostics (#240) * (feat) better error diagnostics Narrow down in which step the error occurs and try to extract better error messages. #86, #232, #129 * (feat) show sv... — committed to sveltejs/language-tools by dummdidumm 4 years ago
I tried this and the problem I run into can be fixed by setting
svelte.language-server.runtime
like @dummdidumm suggested. @JoeBobMiles you can try to requirenode-sass
in a js file and run the file with node to see if there are any errors.It is documented and the warning in the IDE does also hint at this.
The “Cannot find any of modules: …” error can appear when the package is not found, because the module resolution did not find it, or because it did find it but the node versions did not match and node-sass then throws an error.
svelte-preprocess
swallows both these errors and just emits “Cannot find any of modules: …”The package.json thing is interesting, need to check on that. It should fall back to the plugin’s built in svelte version. Apart from that, this does work today already for typescript only. You need to delete the svelte.config.js completely. A fallback is used then which should be able deal with typescript but not more. This is not documented because right now there is just too much fluctuation in that area.
Ah, I see. I will get the new log when I am next able then.