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

additionalPages plugin option does not support async function #1077

Closed
1 task done
janvennemann opened this issue Dec 6, 2018 · 3 comments · Fixed by #1080
Closed
1 task done

additionalPages plugin option does not support async function #1077

janvennemann opened this issue Dec 6, 2018 · 3 comments · Fixed by #1080

Comments

@janvennemann
Copy link
Contributor

  • I confirm that this is a issue rather than a question.

Bug report

Trying to use an async function for additionalPages as described in the docs crashes with the following error:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.parse (path.js:1434:5)
    at Object.parse (/Users/jvennemann/Development/appc/titanium-vuepress-docs/node_modules/upath/build/code/upath.js:55:33)
    at Page.get filename [as filename] (/Users/jvennemann/Development/appc/titanium-vuepress-docs/node_modules/@vuepress/core/lib/prepare/Page.js:150:17)
    at Page.get strippedFilename [as strippedFilename] (/Users/jvennemann/Development/appc/titanium-vuepress-docs/node_modules/@vuepress/core/lib/prepare/Page.js:175:24)
    at Page.get slug [as slug] (/Users/jvennemann/Development/appc/titanium-vuepress-docs/node_modules/@vuepress/core/lib/prepare/Page.js:161:25)
    at Page.buildPermalink (/Users/jvennemann/Development/appc/titanium-vuepress-docs/node_modules/@vuepress/core/lib/prepare/Page.js:219:20)
    at Page.process (/Users/jvennemann/Development/appc/titanium-vuepress-docs/node_modules/@vuepress/core/lib/prepare/Page.js:139:10)
    at AppContext.addPage (/Users/jvennemann/Development/appc/titanium-vuepress-docs/node_modules/@vuepress/core/lib/prepare/AppContext.js:294:16)
    at Promise.all.pluginAPI.options.additionalPages.values.map (/Users/jvennemann/Development/appc/titanium-vuepress-docs/node_modules/@vuepress/core/lib/prepare/AppContext.js:108:20)
    at Array.map (<anonymous>)
    at AppContext.process (/Users/jvennemann/Development/appc/titanium-vuepress-docs/node_modules/@vuepress/core/lib/prepare/AppContext.js:107:53)

Version

v1.0.0-alpha.27

Steps to reproduce

  1. npm i -g vuepress
  2. Create a new plugin with the docs example, e.g. as ./docs/.vuepress/plugins/pages.js
module.exports = {
  async additionalPages () {
    const rp = require('request-promise');

    // VuePress doesn't have request library built-in
    // you need to install it yourself.
    const content = await rp('https://github.com/vuejs/vuepress/blob/master/CHANGELOG.md');
    return [
      {
        path: '/readme/',
        content
      }
    ]
  }
}
  1. Add the plugin to the config
module.exports = {
  plugins: [
    require('./plugins/pages')
  ]
}
  1. echo "# Dummy" > ./docs/README.md
  2. vuepress build ./docs

What is expected?

The build runs without error and the additional pages are available

What is actually happening?

The build crashes. See the error above.

Other relevant information

  • Your OS: macOS 10.14
  • Node.js version: v10.13.0
  • Browser version: Chrome
  • Is this a global or local install? local
  • Which package manager did you use for the install? npm
@spiltcoffee
Copy link
Contributor

This should actually be a feature request, since vuepress doesn't state it supports remotely loading pages like this currently.

When are you expecting the markdown file in your example to be consumed? At build? Or when you request the page?

@janvennemann
Copy link
Contributor Author

Well, it's is in the docs so i was expecting this to work. The plugin should load the content during build and then the page is available just like a local page.

I actually need this to add additional local pages backed by existing markdown files, but in a async way. More precisely just like it is done here only that the pages reside in a different source folder.

I already worked on a fix that enables async functions, which i can provide shortly.

@spiltcoffee
Copy link
Contributor

My bad, didn't notice the exact async example you used was from the docs. >.<

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

Successfully merging a pull request may close this issue.

2 participants