Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global vuepress fail to resolve custom theme #392

Closed
meteorlxy opened this issue May 10, 2018 · 11 comments
Closed

Global vuepress fail to resolve custom theme #392

meteorlxy opened this issue May 10, 2018 · 11 comments

Comments

@meteorlxy
Copy link
Member

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?

@hmatalonga
Copy link
Contributor

hmatalonga commented May 10, 2018

Perhaps something like autoloading the theme folder from npm registry by fetching it would be nice or maybe change the documentation saying that if you specify a custom theme (which isn't local) you have to yarn add vuepress-theme-something.

@meteorlxy
Copy link
Member Author

meteorlxy commented May 10, 2018

@hmatalonga Come on!

The 2nd solution produces the same problem (from my short testing) since when add vuepress, no theme dependency is added, it will still be missing the vuepress-theme-vue/Layout.vue as the folder doesn't exist anywhere.

Look at the last line of the first step to repro it:

yarn add vuepress-theme-vue

Although you add the theme locally, you cannot use it via global vuepress.

I just took vuepress-theme-vue for example, you could change it to vuepress-theme-test to have a try.

@hmatalonga
Copy link
Contributor

@meteorlxy my apologies, I don't known how I how missed the first steps... I removed my dumb comments from the previous message xD

Anyway for using it via global vuepress does the idea of somehow fetching the theme contents makes sense to you?

@meteorlxy
Copy link
Member Author

@hmatalonga
As a global cli, it should work, I think.

In my opinion, we must consider every possible & sensible scenario

@ulivz
Copy link
Member

ulivz commented May 10, 2018

In my opinion, we must consider every possible & sensible scenario

once again, I want to emphasize the intention of Evan: VuePress is mainly for vuejs.

So we don't have to think about all possible scenarios.

@meteorlxy
Copy link
Member Author

@ulivz Sorry but I didn't get what you mean here.

When using global vuepress, you have to make the theme global. That's unreasonable

@meteorlxy
Copy link
Member Author

So I use "sensible" together. Not all possible scenarios should we consider, but those sensible ones.

@ulivz
Copy link
Member

ulivz commented May 10, 2018

I don't think this feature is sensible. If you just want to play around with VuePress, you can install it globally. but since you have a custom theme installed at local, why not installing VuePress at local too?

@meteorlxy
Copy link
Member Author

"If you just want to play around with VuePress" - and try some different themes randomly - this is sensible.

Just because that we don't have various themes now

@ulivz
Copy link
Member

ulivz commented May 10, 2018

If you just want to play around with VuePress, and try some different themes randomly

it makes sense.

@cfharyadi
Copy link

Hi @ulivz @meteorlxy ,
I update my vuepress global-cli to version 0.10.0 and follow folder structure from @meteorlxy above, then I run 'vuepress dev src' but still produce error, the same as point.5 above.

However if I modify ~/.config/yarn/global/node_modules/vuepress/lib/prepare.js and add
path.resolve('node_modules') in the paths array
as in
paths: [ path.resolve(__dirname, '../node_modules'), path.resolve('node_modules'), path.resolve(sourceDir) ]

It fix the error, I guess it resolve the theme location within main project working directory node_modules folder, if that make sense?
What do you think? or did I miss something?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants