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

Treat missing source map sources as non-fatal during SSR #2892

Closed
arseneyr opened this issue Apr 7, 2021 · 6 comments
Closed

Treat missing source map sources as non-fatal during SSR #2892

arseneyr opened this issue Apr 7, 2021 · 6 comments
Labels
enhancement New feature or request feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@arseneyr
Copy link

arseneyr commented Apr 7, 2021

Clear and concise description of the problem

Some NPM packages include source maps that reference sources which were not included as part of the package. For example, the Material Components reference the original Typescript sources in their source maps. When loading such a module for SSR, the missing sources cause Vite to throw an error.

A simple repro (after installing vite and @material/ripple):

const {createServer} = require('vite');

async function run() {
  const vite = await createServer();
  vite.ssrLoadModule('@material/ripple');
}

run();

results in:

node:internal/process/promises:218
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[Error: ENOENT: no such file or directory, open '/home/repos/vite-issue/node_modules/@material/ripple/index.ts'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/repos/vite-issue/node_modules/@material/ripple/index.ts'
}

Suggested solution

Ignore missing sources in source maps.

Additional context

I ran into this issue when trying to set up SvelteKit with Material Components. I think it's not uncommon for packages to not ship sources that are referenced in source maps so it would be nice for Vite to ignore such situations instead of having package authors fix their source maps.

@Shinigami92 Shinigami92 added the p2-nice-to-have Not breaking anything but nice to have (priority) label Apr 7, 2021
@unlocomqx
Copy link

Encountered the same issue with svelte material where @material/drawer doesn't ship the ts files
Repro
https://github.com/unlocomqx/vite-sourcemap-error
This causes a fatal error when serving the page in dev mode

@benmccann
Copy link
Collaborator

I hope it would continue to warn, but I agree this should not be an error. It is helpful to know when source maps are broken so that they can be fixed. Supabase fixed their sourcemaps as a result of this being surfaced supabase/supabase-js#153

@mscolnick
Copy link

This is breaking for me as well, and no clear path to fix - there are a fair amount of dependencies with bad source maps that make it difficult to fix 1 by 1.

Is there a way to disable source maps from node_modules?

@unlocomqx
Copy link

@mscolnick best way rn is to delete sourcemaps from node_modules, something like this could work

// add to package.json scripts
"prepare": "npm run vite-workaround",
"vite-workaround": "find node_modules/ -name \"*.js.map\" -type f -delete"

@mscolnick
Copy link

@unlocomqx thanks for the suggestions, although, we are in a Bazel monorepo right now which makes that quite difficult and would effect other non-Vite projects

@bluwy bluwy added the feat: ssr label Mar 6, 2022
@bluwy
Copy link
Member

bluwy commented Mar 6, 2022

This seems to be fixed now. Here's a stackblitz link to reproduce it. The logs now show:

Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/ripple/index.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/ripple/util.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/ripple/adapter.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/ripple/constants.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/ripple/types.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/ripple/foundation.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/ripple/component.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/base/foundation.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/dom/events.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/dom/ponyfill.js" points to missing source files
Sourcemap for "/home/projects/node-zfq2wn/node_modules/@material/base/component.js" points to missing source files

without crashing.

@bluwy bluwy closed this as completed Mar 6, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

No branches or pull requests

7 participants