vuepress: vuepress build docs Error

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

Bug report

Version

  • 0.14.9

Steps to reproduce

vuepress build docs

What is expected?

What is actually happening?

image

Other relevant information

  • Your OS: Mac OS
  • Node.js version: v11.2.0
  • Browser version: chrome 72.0.3626.109
  • Is this a global or local install? global install
  • Which package manager did you use for the install? npm

Please help me with a look

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (1 by maintainers)

Most upvoted comments

@Pearyman 你的问题和我当时遇到的一样,当时我是想全局引入一个vueparticle的组件,你是想找vuepress的入口文件哇,想全局引入组件是吧,建议你使用vuepress1.x的文档,看这篇教程 https://vuepress.vuejs.org/zh/guide/custom-themes.html#应用配置

import Vue from 'vue';
import AppTest from './components/AppTest';

export default (({
  Vue
}) => {
  Vue.use(AppTest)
});

Ummmm I think you might misunderstand me.

Some vuepress plugins actually need a browser environment, which is the reason for the error you encounted:

require('element-ui') // Error: window is not defined

So if a module cannot be “required” directly from Node, it cannot be used in vuepress, unless it is imported in the mounted hook like this:

export default {
  mounted() {
    import('element-ui').then(/* things to do next */)
  }
}

Having found another way ,it was solved.

import Vue from 'vue'
import VueHighlightJS from 'vue-highlight.js'
import 'highlight.js/styles/atom-one-dark.css'
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '../.vuepress/public/css/index.css'
import {MyComponent} from 'mymodule/packages/MyComponent'
export default ({
  Vue, 
  options, 
  router, 
  siteData
}) => {
  Vue.use(VueHighlightJS)
  Vue.use(Element)
  Vue.component('MyComponent',MyComponent)
}

it works for me when i run vuepress build