vuejs / vitepress

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

Vitepress is unable to build website when installed in workspace #3677

Closed N0W0RK closed 1 month ago

N0W0RK commented 1 month ago

Describe the bug

When using vitepress in a yarn workspace, the build script erorrs. Depending on the setup, there are issues importing vue or even vitepress itself.

Reproduction

mkdir -p monorepo/docs
cd monorepo
yarn init -2
echo "{\"name\": \"Monorepo\", \"packageManager\": \"yarn@4.1.1\",  \"workspaces\": [\"./docs\"]}" > package.json
echo "{\"name\": \"my-workspace\"}" > docs/package.json
yarn workspace my-workspace add -D vue vitepress
cd docs
npx vitepress init
cd ..
yarn workspace my-workspace docs:build

Expected behavior

Clean build of the static website.

System Info

OS: Manjaro Linux; 6.6.19-1-MANJARO 
node: v21.6.2
yarn: v4.1.1
vitepress: v1.0.0
vue: v3.4.21

Additional context

No response

Validations

brc-dd commented 1 month ago

Add this to .vitepress/config:

import { defineConfig } from 'vitepress'
import { createRequire } from 'node:module'

const require = createRequire(import.meta.url)

export default defineConfig({
  // ...

  vite: {
    resolve: {
      alias: {
        'vue/server-renderer': require.resolve('vue/server-renderer'),
        'vue': require.resolve('vue')
      }
    }
  }
})

Will be fixed in next version.