question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript Error: No element indexed by 0

See original GitHub issue

This 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:closed
  • Created 3 years ago
  • Comments:26 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
dummdidummcommented, Mar 12, 2021

I dug into this at well and I’m suspecting the Svelte compiler now and how it handles incoming sourcemap, or how that sourcemap is produced by Svelte’s preprocessor.

I noticed that when you run a preprocessor before compiling

  • the js.map is a class SourceMap instead of a JSON
  • that class has empty sources and sourcesContent arrays, whereas without preprocessing they are set and filled

EDIT: 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 if sourcemap is set. Or sourcemap contains a wrong sources content, which means the compiler’s preprocess function is at fault.

1reaction
dominikgcommented, Mar 11, 2021

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found