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: handle non-existing files in sourcemap #4328

Closed
wants to merge 2 commits into from

Conversation

HerringtonDarkholme
Copy link
Contributor

@HerringtonDarkholme HerringtonDarkholme commented Jul 20, 2021

Description

If a source map contains a file in source section without uploading the referenced file, Vite will complain about ENOENT.
This fix makes Vite more lenient with npm ecosystem's misdemeanor.

Additional context

When a npm package's source map has a source field, Vite will resolve the referenced file. However, not all packages will upload the source to npm registry, which makes such error. For example, the package compute-scroll-into-view does have such sources field.

image

And vite throws an error.

image

Instead of throwing an error, this fix makes Vite ignore the missing source file.
To make the output less noisy and make the build successful, a comment is added for possible suggestion in the emitted source map. This supersedes #2904.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

If a source map contains a file in `source` section without uploading the referenced file, Vite will complain about ENOENT.
This fix makes Vite more lenient with npm ecosystem's misdemeanor.
Instead of emitting error, forging a source file with a comment as hint.
@patak-dev patak-dev added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jul 20, 2021
@aleclarson
Copy link
Member

aleclarson commented Jul 21, 2021

Thanks, but I'd rather the devtools show the compiled code instead of a mostly useless comment.

I've updated #2904 to warn just once per sourcemap instead of throwing an error. It uses logger.warnOnce to ensure the same warning is never printed twice. You can even use DEBUG="vite:sourcemap" to log the list of missing sources after each warning. Let me know if that approach is good enough for you.

@aleclarson aleclarson closed this Jul 21, 2021
@HerringtonDarkholme
Copy link
Contributor Author

Thanks.

Thanks, but I'd rather the devtools show the compiled code instead of a mostly useless comment.

But I'd rather argue warning in devtools is, well, equally useless and a debugging log is too hard to find after a flag.(finding th flag is not discoverable unless one reads the source).

But whatever, no blocking the build is enough for most devs and hope #2904 gets merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants