vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.17k stars 2.12k forks source link

Compilation errors occur in some special cases #449

Closed keuby closed 2 years ago

keuby commented 2 years ago

Describe the bug

The MD content contains the following code build error

## Properties

| Property | Type                                 |
| -------- | ------------------------------------ |
| icon     | { active: string; default: string; } |
yarn run v1.22.11
$ vitepress build docs
vitepress v0.20.0
⠋ building client + server bundles...[vite:vue] Duplicate attribute.
file: /vitepress-bug-demo/docs/index.md:5:42
✖ building client + server bundles...
[vite:vue] Cannot read property 'line' of undefined
file: /vitepress-bug-demo/docs/index.md
build error:
 SyntaxError: Duplicate attribute.
    at createCompilerError (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:19:19)
    at emitError (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:1599:29)
    at parseAttribute (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:1340:9)
    at parseAttributes (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:1316:22)
    at parseTag (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:1186:17)
    at parseElement (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:1115:21)
    at parseChildren (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:943:28)
    at parseElement (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:1131:22)
    at parseChildren (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:943:28)
    at parseElement (/vitepress-bug-demo/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:1131:22) {
  code: 'PLUGIN_ERROR',
  loc: {
    file: '/vitepress-bug-demo/docs/index.md',
    line: 5,
    column: 42
  },
  id: '/vitepress-bug-demo/docs/index.md',
  plugin: 'vue',
  hook: 'transform',
  pluginCode: 2,
  watchFiles: [
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/app/index.js',
    '/vitepress-bug-demo/docs/index.md',
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/app/utils.js',
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/app/router.js',
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/app/data.js',
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/app/composables/head.js',
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/app/composables/preFetch.js',
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/app/components/Content.js',
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/app/components/ClientOnly.js',
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/app/components/Debug.vue',
    '/vitepress-bug-demo/node_modules/vue/dist/vue.runtime.esm-bundler.js',
    '/vitepress-bug-demo/node_modules/vitepress/dist/client/theme-default/index.js'
  ]
}

Reproduction

https://github.com/keuby/vitepress-bug-demo.git

Expected behavior

Build does not report errors

System Info

System:
    OS: macOS 11.6
    CPU: (8) arm64 Apple M1
    Memory: 121.91 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v14.17.6/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm
  Browsers:
    Chrome: 96.0.4664.55
    Edge: 95.0.1020.53
    Firefox: 90.0
    Safari: 15.0
  npmPackages:
    vitepress: ^0.20.0 => 0.20.0 


### Additional context

_No response_

### Validations

- [X] Follow our [Code of Conduct](https://vuejs.org/coc)
- [X] Read the [docs](https://vitepress.vuejs.org/).
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
keuby commented 2 years ago

The above content will be compiled like this

  <tr>
      <td>icon</td>
      <td active:="" string;="" default:="" string;=""></td>
  </tr>
norskeld commented 2 years ago

Not sure about the reason (I think it's related to interpolation in Markdown files, but you can easily workaround this by enclosing this piece { active: string; default: string; } in backticks, so it's treated like an inline code block.

This compiles just fine:

## Properties

| Property | Type                                   |
| -------- | -------------------------------------- |
| icon     | `{ active: string; default: string; }` |
keuby commented 2 years ago

Not sure about the reason (I think it's related to interpolation in Markdown files, but you can easily workaround this by enclosing this piece { active: string; default: string; } in backticks, so it's treated like an inline code block.

This compiles just fine:

## Properties

| Property | Type                                   |
| -------- | -------------------------------------- |
| icon     | `{ active: string; default: string; }` |

But the content is automatically generated by the @microsoft/api-documenter

kiaking commented 2 years ago

Confirmed. Not sure how to fix, but we wanna fix.

brc-dd commented 2 years ago

Can now be done by disabling markdown-it-attrs. Ref. #664

Output:

image

kiaking commented 2 years ago

Niice! Thanks for the confirmation 🙌 🙌 🙌 I think disabling attrs plugin is only logical way to go around this issue.