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(plugin-vue): misleading error thrown after refresh or hmr #5870

Merged
merged 2 commits into from
Nov 28, 2021

Conversation

y1d7ng
Copy link
Contributor

@y1d7ng y1d7ng commented Nov 28, 2021

Description

fix #5771
correct error displayed:

[vite] Internal server error: Element is missing end tag.
  Plugin: vite:vue
  File: repro/src/components/HelloWorld.vue

after refresh or hmr:

[vite] Internal server error: Cannot read property 'line' of undefined
  Plugin: vite:vue
  File: repro/src/components/HelloWorld.vue

Additional context

The error comes from the result of the execution of compiler.parse:

const { descriptor, errors } = compiler.parse(source, {
filename,
sourceMap
})

compiler.parse will cache the execution results:
https://github.com/vuejs/vue-next/blob/2d4f4554349db6b07027d0c626f56c48d0233f67/packages/compiler-sfc/src/parse.ts#L105-L110
https://github.com/vuejs/vue-next/blob/2d4f4554349db6b07027d0c626f56c48d0233f67/packages/compiler-sfc/src/parse.ts#L274-L278

Changing the loc of the cached error here will throw a new error(Cannot read property 'line' of undefined) the next time it is executed:

;(error as any).loc = {
file: id,
line: error.loc.start.line,
column: error.loc.start.column
}


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.

patak-dev
patak-dev previously approved these changes Nov 28, 2021
@antfu antfu merged commit 5c07cec into vitejs:main Nov 28, 2021
@y1d7ng y1d7ng deleted the fix-5771 branch November 28, 2021 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misleading error thrown when html end tag is missing (plugin-vue)
5 participants