-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
$page is an illegal variable name #652
Comments
This also happens for a custom store (in my case Also Svelte 5, Eslint, TS. |
is there a workaround? btw, where is the source of the |
I'm not entirely sure if this is correct, but I was able to find a workaround using the following method:
|
Is it possible to disable this error? |
As you may already know, the @RyousukeUchino proposal may suppress warnings, but is not recommended in hot code paths. https://svelte.dev/docs/svelte-store#get
|
The following can be used as a workaround Disable in one line<script>
import { page } from '$app/stores';
// eslint-disable-next-line svelte/valid-compile
const currentPagePath = $page.url.pathname;
</script> Disable in project.eslintrc.cjs module.exports = {
// ...
rules: {
"svelte/valid-compile": "off"
}
} Check here for additional details |
The |
This plugin appears to be incorrectly transforming the Something like <script>
import { page } from '$app/stores';
</script> is getting transformed into <script>import '$app/stores';
//# sourceMappingURL=module.js.map
</script> presumably because it's only operating on the Putting a bare reference to <script>
import { page } from '$app/stores';
page;
</script> gets transformed into <script>import { page } from '$app/stores';
page;
//# sourceMappingURL=module.js.map
</script> but the real solution is going to be fixing this transformation that the plugin does to the script tag before passing it to the Svelte compiler. If this is related to TypeScript, I think the solution is going to be to just stop running the |
I tried adding page as a global in eslint config not a big deal though |
From @Conduitry's investigation my shot in the dark is that |
@dummdidumm In Svelte 5, is there a reason to transpile the |
I don't think so, the Svelte 5 compiler natively supports Typescript (now even in the template, not just the script tag). |
I'm running into this as well. |
I tried setting |
It doesn't fully support all TS features, decorators and enums among them, so there might still be a need to preproccess the files beforehand. |
Went about converting my app from Svelte 4 -> 5 today, update process was fairly smooth, but the eslint errors in this ticket are showing up. Would be good to see a proper fix for this that doesn't involve disabling eslint checks everywhere |
Still getting this error with |
Use |
I still get this error with :
But this looks more like a vite-plugin-svelte problem EDIT : It seems like https://github.com/sveltejs/svelte-preprocess doesn't support Svelte 5? I switched to VitePreprocess and now it works. |
Before You File a Bug Report Please Confirm You Have Done The Following...
What version of ESLint are you using?
8.56.0
What version of
eslint-plugin-svelte
are you using?2.36.0-next.3
What did you do?
Configuration
pnpm create svelte@latest
pnpm i -D eslint-plugin-svelte@next
What did you expect to happen?
$page
to be a legal variable nameWhat actually happened?
4:14 error $page is an illegal variable name. To reference a global variable called $page, use globalThis.$page(illegal-global) svelte/valid-compile
Link to GitHub Repo with Minimal Reproducible Example
https://github.com/huntabyte/s5-illegal-variable-repro
Additional comments
I noticed this only occurs when using Typescript. If I go through the create svelte flow and choose "Javascript with JSDoc" everything is good.
The text was updated successfully, but these errors were encountered: