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

LSP Diagnostics error "... is an illegal variable name" on Neovim #2326

Closed
pierregoutheraud opened this issue Mar 28, 2024 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@pierregoutheraud
Copy link

pierregoutheraud commented Mar 28, 2024

Describe the bug

My code works fine but I am getting a diagnostics error on Neovim using svelte-language-server@0.16.6 and svelte@5.0.0-next.1:

$myStore is an illegal variable name. To reference a global variable called $myStore, use globalThis.$myStore(illegal-global) [svelte/valid-compile]

This only happens when using svelte 5 and in neovim and not vscode.
I am getting this error displayed whenever I am using a store inside a .svelte layout or page.

Example:

// stores/test.ts
import { writable } from 'svelte/store';
export const myStore = writable(0);
// +layout.svelte
<script lang="ts">
  import { onMount } from 'svelte';
  import { myStore } from '../stores/test';
  onMount(() => {
    $myStore = 1; <--- ERROR here
  });
</script>

Reproduction

Reproduction minimal repo: https://github.com/pierregoutheraud/test-svelte5

Versions used:

		"@sveltejs/adapter-auto": "^3.0.0",
		"@sveltejs/kit": "^2.0.0",
		"@sveltejs/vite-plugin-svelte": "^3.0.0",
		"@types/eslint": "^8.56.0",
		"@typescript-eslint/eslint-plugin": "^7.0.0",
		"@typescript-eslint/parser": "^7.0.0",
		"eslint": "^8.56.0",
		"eslint-config-prettier": "^9.1.0",
		"eslint-plugin-svelte": "^2.36.0-next.4",
		"prettier": "^3.1.1",
		"prettier-plugin-svelte": "^3.1.2",
		"svelte": "^5.0.0-next.1",
		"svelte-check": "^3.6.0",
		"tslib": "^2.4.1",
		"typescript": "^5.0.0",
		"vite": "^5.0.3",
		"vitest": "^1.2.0"

Expected behaviour

No diagnostics error.

System Info

  • OS: Mac
  • IDE: Neovim

Which package is the issue about?

svelte-language-server

Additional Information, eg. Screenshots

No response

@pierregoutheraud pierregoutheraud added the bug Something isn't working label Mar 28, 2024
@jasonlyu123
Copy link
Member

I can't reproduce this. Can you remove your language server installation and its node_modules and try again?

@pierregoutheraud
Copy link
Author

pierregoutheraud commented Mar 31, 2024

@jasonlyu123 I use Mason to install my LSPs, so I already tried re-installing svelte-language-server without success.
I am not sure what you mean by "its node_modules", you mean the svelte project node_modules? If yes, I tried that also yes.

I am getting the same error with yarn eslint . so I guess the issue is coming from eslint-plugin-svelte and not the LSP.
This is related to sveltejs/eslint-plugin-svelte#652.

@jasonlyu123
Copy link
Member

The language server is a node package with dependencies. What I meant is the node_modules for these dependencies. But when using Svelte 5, the Svelte language server loads the Svelte compiler user installed in their project. So if there is a dependency problem, it is more likely from the node_modules in your project.

I am closing this since it does seem like it's from eslint. I can reproduce the error with lint but not with editor or svelte-check. Feel free to add more info if it turns out to be the svelte language server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants