Skip to content
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

fix: Sourcemap for "/path/to/Component.svelte" points to missing source files #621

Closed

Conversation

bfanger
Copy link
Contributor

@bfanger bfanger commented Apr 14, 2023

When using Vite's css.devSourcemap: true and using <style lang="scss"> processed with vitePreprocess will result in broken source maps for the css.

Example vite log:

Sourcemap for "/Volumes/Sites/svelte-project/src/routes/+page.svelte" points to missing source files

This is caused by the the fake filename that is passed to the transform function (which is needed so vite will select the appropriate transformation).

This PR repairs the SourceMap to use the original filename.

@dominikg
Copy link
Member

thank you for posting this. Please add a changeset with pnpm changeset and it would also be great if there was at least a reproduction repo or even better a testcase that shows this is working as intended afterwards.

@bfanger bfanger force-pushed the fix/sourcemap-missing-source-files branch from bdfc423 to e14bae1 Compare April 14, 2023 16:36
@bfanger
Copy link
Contributor Author

bfanger commented Apr 14, 2023

Interesting, the sourcemap from the unittest i'm writing does use relative paths and a sourceRoot before it is processed by the mapSourcesToRelative():

{
  version: 3,
  sourceRoot: '/Volumes/Sites/vite-plugin-svelte/packages/e2e-tests/css-dev-sourcemap/src',
  sources: [ 'App.svelte.scss' ],
  names: [],
  mappings: 'AAEE;EACC',
  file: 'App.svelte.scss'
}

@bfanger bfanger force-pushed the fix/sourcemap-missing-source-files branch from e14bae1 to 6eeab48 Compare April 14, 2023 18:34
@bfanger
Copy link
Contributor Author

bfanger commented Apr 14, 2023

I've added an e2e test, so it keeps working as intended #305 😉.
Feel free to contact me when new SourceMap issues arise.

Tip: If you paste the contents of the snapshot from
packages/e2e-tests/css-dev-sourcemap/__tests__/__snapshots__/css-dev-sourcemap.spec.ts.snap
Into the Source Map Visualization tool you'll see it now working as intended:
source-map-visualization

@dominikg
Copy link
Member

Thanks for adding the testcase. I'm not sure using a sourcemap visualizer to be able to understand the snapshot is a good idea as it puts extra work on the maintainers every time the snapshot changes to find out why exactly it suddenly failed.

A unit test calling vitePreprocess().style directly could be better.

The filenames being relative already could be vite having improved in the meantime or because this is css and it's only a simple input. If there was additional config, eg a banner or scss imports leading to more entries in map.sources, the situation could be different.

For this PR I think it is sufficient to make sure that the extra lang suffix is stripped from the file refs in map

@dominikg
Copy link
Member

refactored it here #625 . @bfanger please take a look. It should cover your case and then some (eg turning map.file into relative as well)

@bfanger
Copy link
Contributor Author

bfanger commented Apr 16, 2023

Closing in favor of the 625

@bfanger bfanger closed this Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants