Skip to content

[Bug] Build fails when srcDir is set to a directory outside project root #4612

Open
@kawamataryo

Description

@kawamataryo

First of all, thank you for creating Vitepress - it's an amazing tool. I really appreciate all the hard work that goes into maintaining it.

Description

When configuring Vitepress with a srcDir that points to a directory outside the project root, the build process fails with a "Rollup failed to resolve import 'vue'" error.

$ vitepress build

  vitepress v1.6.3

x Build failed in 12ms
✖ building client + server bundles...
build error:
[vite]: Rollup failed to resolve import "vue" from "/xxxxx/vitepress-src-dir-bug/api-examples.md".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
[vite]: Rollup failed to resolve import "vue" from "/xxxxx/vitepress-src-dir-bug/api-examples.md".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`

Reproduction

I've created a reproduction repository: vitepress-src-dir-bug

Reproduce step

$ git clone  https://github.com/kawamataryo/vitepress-src-dir-bug
$ cd vitepress-example
$ yarn
$ yarn docs:dev // It work
$ yarn docs:build // It don't work

Expected behavior

Vitepress should successfully build the documentation regardless of the srcDir location.

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M2
    Memory: 449.28 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.17.0 - ~/.asdf/installs/nodejs/20.17.0/bin/node
    Yarn: 1.22.22 - ~/.asdf/installs/nodejs/20.17.0/bin/yarn
    npm: 10.8.2 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 10.3.0 - ~/.asdf/installs/nodejs/20.17.0/bin/pnpm
    bun: 1.0.29 - /opt/homebrew/bin/bun
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 133.0.6943.143
    Edge: 134.0.3124.51
    Safari: 17.5

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions