Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(vite): include importer in vite-node error stack #7607

Merged
merged 1 commit into from Sep 19, 2022
Merged

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Sep 16, 2022

πŸ”— Linked issue

Ref nuxt/nuxt#14909

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR tries to include (last) importer in stack traces of vite-node formatted errors.

image

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Sep 16, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit 0f9f3f1
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/6324bff70a7e3c0008b9bc33

@pi0 pi0 requested review from antfu and danielroe September 16, 2022 18:27
return new ViteNodeRunner({
root: viteNodeOptions.root, // Equals to Nuxt `srcDir`
base: viteNodeOptions.base,
resolveId (id, importer) { _importers.set(id, importer) },
async fetchModule (id) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antfu is it possible for vite-node to directly give importer to the fetchModule? It could be useful to format errors better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that a module could be imported by multiple importers and vite-node caches them to reuse the existing one. That means if we could have the importer it could only be the first one hit the module and can be changed in different requests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Indeed makes sense. But how do you think about this solution for Nuxt to hint about error? I suppose first importer triggers the error this way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could update the logging message to be something like (first imported by x) to keep it accurate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having imported by is also accurate (it could be, also imported by y but as result of being imported by x is now being failed). Similar to other stack traces if a util is used by two functions, first function calling it shows in stack trace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will see what I can do on the vite-node side

@pi0 pi0 changed the title fix(vite-node): include importer in error stack fix(vite): include importer in vite-node error stack Sep 16, 2022
@pi0 pi0 merged commit 57a8a86 into main Sep 19, 2022
@pi0 pi0 deleted the fix/vite-error-trace branch September 19, 2022 09:28
@pi0 pi0 mentioned this pull request Sep 20, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants