Skip to content

Global vuepress fail to resolve custom theme #392

Closed
@meteorlxy

Description

@meteorlxy

Here's the simplest way to repro it:

  1. Add a custom theme (take vuepress-theme-vue for example) to a new repo:
mkdir testrepo
cd testrepo
yarn add vuepress-theme-vue
  1. Create src and base files, then the directory will be like this:
+-- src/
|   +-- .vuepress/
|       +-- config.js
|   +-- README.md
+-- node_modules
|   +-- vuepress-theme-vue/
+-- package.json
+-- yarn.lock
  1. Set theme to vue in config.js
module.exports = {
  theme: 'vue'
}
  1. Run global vuepress
vuepress dev src
  1. Error
Error: [vuepress] Failed to load custom theme "vue". File vuepress-theme-vue/Layout.vue does not exist.
  1. Possible solutions
  • Install custom theme globally (i.e. yarn global add vuepress-theme-vue
  • (Or) Install vuepress locally (i.e. yarn add vuepress) and run it locally (i.e. yarn vuepress dev src)

The cause is that we are using require.resolve() to resolve custom theme:

vuepress/lib/prepare.js

Lines 139 to 140 in 145cf4f

themeLayoutPath = require.resolve(`vuepress-theme-${siteConfig.theme}/Layout.vue`)
themePath = path.dirname(themeLayoutPath)

Is there a better solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions