sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.2k stars 195 forks source link

Language server in VSCode is crashing in a loop #574

Closed mcmxcdev closed 3 years ago

mcmxcdev commented 3 years ago

Describe the bug As soon as I start VSCode, the language server crashes on initialize. I had this issue a while ago, but it went away again after some extension updates I asume, now resurfaced.

As you can see it is not related to actual file content, since it also breaks on a simple <div>hello</div>

To Reproduce Steps to reproduce the behavior:

Expected behavior Svelte VSCode extension to work flawlessly.

Screenshots 2020-09-26_09-18

System (please complete the following information):

dummdidumm commented 3 years ago

Did you change any of the default settings? Like setting the node runtime?

mcmxcdev commented 3 years ago

No, only using default settings. Node version in use is v14.11.0

mcmxcdev commented 3 years ago

You can find the whole codebase that is throwing the error here: https://github.com/mhatvan/markushatvan.com

dummdidumm commented 3 years ago

Does the issue occur if you disable all other extensions in VS Code?

mcmxcdev commented 3 years ago

Just verified that it also happens with a clean VSCode insiders install. Only plugin installed is Svelte VSCode and it crashes on any file.

dummdidumm commented 3 years ago

I cannot reproduce this unfortunately. Googling this only turned up obscure errors with packages that interact with Node on a very low level (using C++ or sth like that). So maybe this build got unlucky with some npm packages installing something that is incompatible with your Node/OS version. Does this error occur when you install an older version of the extension? You can do so by right-clicking on the installed extension and then select "Install another Version". Alternatively, wait 20 more hours, then I'll release a new version.

mcmxcdev commented 3 years ago

Yeah, I also don't find any solutions for this. Downgrading to older Svelte VSCode versions and/or an older Node version still produces this error unfortunately.

mcmxcdev commented 3 years ago

When running the project on macOS, no errors are encountered. So it is probably a Linux/Ubuntu specific issue.

mcmxcdev commented 3 years ago

I was able to find out what causes the issue!

This is my svelte.config.js:

const sveltePreprocess = require('svelte-preprocess');
const postcss = require('./postcss.config');
const image = require('svelte-image');
const { mdsvex } = require('mdsvex');

const defaults = {
  script: 'typescript',
  style: 'postcss',
};

const createPreprocessors = ({ sourceMap }) => [
  mdsvex(),
  image({ placeholder: 'blur', optimizeRemote: true }),
  sveltePreprocess({
    defaults,
    sourceMap,
    postcss,
    preserve: ['ld+json'],
  }),
];

module.exports = {
  createPreprocessors,
  // Options for `svelte-check` and the VS Code extension
  preprocess: createPreprocessors({ sourceMap: true }),
};

When I comment out the svelte-image import and its usage in createPreprocessors, the Svelte VSCode extension loads just fine.

Unfortunately, I cannot pinpoint why svelte-image is causing an issue all of a sudden, the last release is back a month.

dummdidumm commented 3 years ago

svelte-image has a dependency on sharp, and in one of the other issues related to this problem someone said that package caused it - maybe for you as well. As a fix: try to leave out the svelte-image preprocessor for the svelte.config.js and only include it for your build config.

mcmxcdev commented 3 years ago

Great that we found the culprit, thanks for the help!

The related core issue: https://github.com/lovell/sharp/issues/2356

I used your suggested fix and all good now.