-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
SSR source map merging fails on empty file segments (Error: No element indexed by 0) #2391
Comments
I've further tracked this down to empty segments of files. That is to say, not only do all loaded files need to be not-empty, in a This will error: <span>Hello world!</span> And so will this: <script>
// just a comment here
</script>
Hello world This will succeed: <script>
let name = 'world';
</script>
<span>Hello {name}!</span> It must have some proper content (i.e. not just comments, not compiled down to nothing) or it will trigger the bug. |
svelte uses ampproject/remapping which is up to date see |
I've gotten some progress on this issue - it's not necessarily empty segments but any static file that does not involve JS processsing. Vite's current code does not handle blank sourcemaps at all. Problem is, when I tried to look at prior art:
Sourcemaps are always properly generated with <!-- this works -->
Hello {'world'}
<!-- this works -->
Hello world
{''}
<!-- this works -->
<script>
let blah = true;
</script>
Hello world
<!-- this works -->
{#each [1, 2, 3] as num}
{num}
{/each}
<!-- this doesn't, cause it's just HTML -->
<h1>Hello world</h1> |
Until #2441 is merged into Vite, anyone running into this can apply the following workaround. WARNING: This is massively hacky and not a good long-term solution. This is intended mostly for people trying out Svelte-Kit via WARNING WARNING WARNING: If you use pnpm, applying the patch below will change not just the copy of Vite in your project's If you use pnpm and want to REMOVE this hacky workaround, all you need to do is run Okay, if you haven't been scared off by the warnings above, here's the hacky workaround. After running --- a/node_modules/vite/dist/node/chunks/dep-e0f09032.js 2021-03-03 02:27:15.000000000 +0700
+++ b/node_modules/vite/dist/node/chunks/dep-e0f09032.js 2021-03-03 02:27:15.000000000 +0700
@@ -25190,7 +25190,12 @@
var sourceRoot = this.sourceRoot;
mappings.map(function (mapping) {
- var source = mapping.source === null ? null : this._sources.at(mapping.source);
+ var source;
+ try {
+ source = mapping.source === null ? null : this._sources.at(mapping.source);
+ } catch (e) {
+ source = null;
+ }
source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
return {
source: source, NOTE: This works on Vite 2.0.5, but future Vite releases will probably use a different filename. If a new Vite release comes out before #2441 gets merged in, you'll have to tweak this patch by hand. The file you need to patch is the largest file in the |
Describe the bug
The following source map merging:
vite/packages/vite/src/node/ssr/ssrTransform.ts
Lines 180 to 186 in 6fae0b7
Given an empty input will throw an error:
Dev mode log
Important to note here that
merge
is an import frommerge-source-map
, which has not been maintained since December 2017. A somewhat (?) related bug report from May 2018 was already filed on its repo: keik/merge-source-map#6, but with no response. This is why I am bringing up the issue in thevite
repository instead, as I do not think it is solvable on the upstream dependency.Reproduction
https://github.com/GrygrFlzr/vite-sourcemap-repro
System Info
vite
version: 2.0.5The text was updated successfully, but these errors were encountered: