vuejs / vitepress

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

bug: Repeated builds doesn't always succeed every time #4130

Closed tianheg closed 3 months ago

tianheg commented 3 months ago

Describe the bug

When building my VitePress site, sometimes will got this error:

✓ building client + server bundles...
✖ rendering pages...
build error:
Cannot read properties of undefined (reading 'some')
TypeError: Cannot read properties of undefined (reading 'some')
    at isChildActive (file:///mnt/disk/MAIN/read/.vitepress/.temp/app.js:2935:28)
    at file:///mnt/disk/MAIN/read/.vitepress/.temp/app.js:2937:43
    at ReactiveEffect.fn (/mnt/disk/MAIN/read/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js:928:13)
    at ReactiveEffect.run (/mnt/disk/MAIN/read/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js:162:19)
    at get value [as value] (/mnt/disk/MAIN/read/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js:940:109)
    at file:///mnt/disk/MAIN/read/.vitepress/.temp/app.js:2942:127
    at renderComponentSubTree (/mnt/disk/MAIN/read/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:442:9)
    at renderComponentVNode (/mnt/disk/MAIN/read/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:386:12)
    at ssrRenderComponent (/mnt/disk/MAIN/read/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:84:10)
    at file:///mnt/disk/MAIN/read/.vitepress/.temp/app.js:2974:19
error: script "build" exited with code 1

Didnot know how to figure it out.

Reproduction

https://github.com/tianheg/read/tree/0a2c670076d0bec5db10500807eb4c31bb5c80da

Expected behavior

build succeed every time

System Info

System:
  OS: Linux 6.10 Arch Linux
  CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  Memory: 13.31 GB / 23.36 GB
  Container: Yes
  Shell: 5.9 - /usr/bin/zsh
Binaries:
  Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
  npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
  bun: 1.1.22 - /usr/bin/bun
npmPackages:
  vitepress: ^1.3.2 => 1.3.2

Additional context

No response

Validations

tianheg commented 3 months ago

Context explained

This problem is caused by the wrong usage of sidebar.

Old config

const sidebar = {
  "/": [
    {
      text: "软件开发+计算机科学",
      collapsed: true,
      items: [
        { text: "Eloquent JavaScript", link: "/eloquent-javascript", score: 5 },

      ],
    },
    {
      text: "人物传记+随笔",
      collapsed: true,
      items: [
        { text: "创新者", link: "/the-innovators" },

      ],
    },
  ],
  "/non-book/": [
    {
      text: "Building Programmable Web Sites",
      link: "/non-book/building-programmable-web-sites",
    },
  ],
};

export default defineConfig({
  themeConfig: {
    sidebar: sidebar,
  },
});

New config

Learn from VitePress official docs config

function sidebarBook() {
  return [
    {
      text: "软硬开发+计算机科学",
      collapsed: true,
      items: [
        { text: "Eloquent JavaScript", link: "eloquent-javascript", score: 5 },
      ],
    },
    {
      text: "人物传记+随笔",
      collapsed: true,
      items: [
        { text: "创新者", link: "the-innovators" },
      ],
    },
  ];
}

function sidebarNonBook() {
  return [
    {
      text: "张云帆与芒格",
      link: "zhang-yunfan-and-munger",
    },
  ];
}

export default defineConfig({
  themeConfig: {
    sidebar: {
      "/": { base: "/", items: sidebarBook() },
      "/non-book/": { base: "/non-book/", items: sidebarNonBook() },
    },
  },
});

Now problem has been solved!

Come and see my current VitePress site structure: https://github.com/tianheg/read/tree/36bb0d0ea7f7f018f3b561e7b999a49e4863991e

brc-dd commented 3 months ago

Both of them behave the same way. You don't need base. If this is fixed then the cause of your issue was likely something else.

tianheg commented 3 months ago

If this is fixed then the cause of your issue was likely something else.

Yeah, you're right.

However no matter how many times I try again, I can't reproduce the error.