TypeScript Error: No element indexed by 0
See original GitHub issueThis is caused by Vite’s source map handling on .svelte
files that are not dynamic files.
As a temporary workaround, make sure to have src/routes/$layout.svelte
with at least some “dynamic” content, e.g.
<slot />
{''}
Describe the bug
As long as svelte-preprocess
is used in svelte.config.cjs
, attempting to run dev mode results in internal errors.
Logs With TypeScript, the page is a plaintext error:
Error: No element indexed by 0
at ArraySet_at [as at] (C:\Users\GrygrFlzr\Documents\projects\sk-36\node_modules\vite\dist\node\chunks\dep-1bdbec90.js:24278:9)
at BasicSourceMapConsumer.<anonymous> (C:\Users\GrygrFlzr\Documents\projects\sk-36\node_modules\vite\dist\node\chunks\dep-1bdbec90.js:25193:67)
at Array.map (<anonymous>)
at BasicSourceMapConsumer.SourceMapConsumer_eachMapping [as eachMapping] (C:\Users\GrygrFlzr\Documents\projects\sk-36\node_modules\vite\dist\node\chunks\dep-1bdbec90.js:25192:14)
at merge (C:\Users\GrygrFlzr\Documents\projects\sk-36\node_modules\vite\dist\node\chunks\dep-1bdbec90.js:26656:18)
at ssrTransform (C:\Users\GrygrFlzr\Documents\projects\sk-36\node_modules\vite\dist\node\chunks\dep-1bdbec90.js:61375:15)
at transformRequest (C:\Users\GrygrFlzr\Documents\projects\sk-36\node_modules\vite\dist\node\chunks\dep-1bdbec90.js:61643:48)
at async instantiateModule (C:\Users\GrygrFlzr\Documents\projects\sk-36\node_modules\vite\dist\node\chunks\dep-1bdbec90.js:67986:10)
To Reproduce
npm init svelte@next
# enable typescript
npm install
npm run dev
Expected behavior No errors out of the box.
Information about your SvelteKit Installation:
npmPackages:
@sveltejs/kit: next => 1.0.0-next.36
svelte: ^3.29.0 => 3.35.0
Severity Unusable dev mode.
Issue Analytics
- State:
- Created 3 years ago
- Comments:26 (26 by maintainers)
Top Results From Across the Web
Jest fails coverage reports with 'No element indexed'
I found that if I set the msw handlers to an empty array, the error doesn't appear. The few tests which require the...
Read more >Tuple type of length has no element at index X in TS
The error "Tuple type of length has no element at index" occurs when you declare a tuple in TypeScript and try to access...
Read more >Build error - Get Help - Vue Forum
Hi,. When I tried to npm run build, I am getting below error. Unhandled rejection Error: No element indexed by 25.
Read more >Array - JavaScript - MDN Web Docs
Returns the index of the first element in the array that satisfies the provided testing function, or -1 if no appropriate element was...
Read more >Documentation - Object Types - TypeScript
function greet ( person : { name : string; age : number }) { ... 0 : opts . ... does not match...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I dug into this at well and I’m suspecting the Svelte compiler now and how it handles incoming
sourcemap
, or how thatsourcemap
is produced by Svelte’s preprocessor.I noticed that when you run a preprocessor before compiling
js.map
is a classSourceMap
instead of a JSONsources
andsourcesContent
arrays, whereas without preprocessing they are set and filledEDIT: The reason is the empty
sources
. If I add the full file path to it manually before handing the map to vite, it works. The Svelte compiler seems to trip up there and not fill it ifsourcemap
is set. Orsourcemap
contains a wrong sources content, which means the compiler’s preprocess function is at fault.I think @dummdidumm was talking about my last comment regarding the vite based preprocessor. We should discuss this elsewhere, i was merely offering another option to narrow down the issue.
It’s very possible the way how vite-plugin-svelte reads the svelte config or how the preprocessors+map are applied in compile is at fault here. (though i took the latter bits from rollup-plugin-svelte)