Closed oodavid closed 2 months ago
This is an issue with svelte-preprocess
which can't distinguish top level script tags from non-top-level ones. Since it has a src
preprocessor where the source this points to is inlined into the top level script tag, it needs that src
to be static and throws an error here - wrongfully.
I've noticed that I'm no longer seeing an issue here.
For reference, here's my package.json (lightly redacted), although I'm not sure when this issue disappeared.
{
"name": "admin2",
"version": "0.0.1",
"engines": {
"node": ">=18.0.0"
},
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"test": "playwright test",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --output human --compiler-warnings 'a11y-distracting-elements:ignore,a11y-click-events-have-key-events:ignore,a11y-no-static-element-interactions:ignore,a11y-no-noninteractive-tabindex:ignore,a11y-autofocus:ignore'",
"check:watch": "npm run check -- --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@playwright/test": "^1.42.1",
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.5.5",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.2",
"sass": "^1.72.0",
"svelte": "^4.2.12",
"svelte-check": "^3.6.8",
"tslib": "^2.6.2",
"typescript": "^5.4.3",
"vite": "^5.2.7",
"eslint-plugin-svelte": "^2.35.1"
},
"type": "module"
}
Describe the bug
Using
<script {src} />
causes a Typescript error. Thestring
type is interpreted asstring | null | undefined
. To fix, we can use `Reproduction
Logs
System Info
Severity
annoyance