vuejs / vuepress

📝 Minimalistic Vue-powered static site generator
https://vuepress.vuejs.org
MIT License
22.57k stars 4.76k forks source link

Build error when import SFC from dependency. #666

Closed nikhilkul closed 6 years ago

nikhilkul commented 6 years ago

Bug report

Version

0.12.0

Steps to reproduce

  1. Clone reproduction repo
  2. yarn install
  3. yarn global add vuepress
  4. yarn docs:build -> Fails with
╰─$ yarn docs:build                                                      130 ↵
yarn run v1.7.0
$ vuepress build docs

 WAIT  Extracting site metadata...
<product2></product2>
[4:51:09 PM] Compiling Client
[4:51:09 PM] Compiling Server
(node:17386) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
<product2></product2>
[4:51:14 PM] Compiled Server in 5s
[4:51:16 PM] Compiled Client in 7s
 WAIT  Rendering static HTML...
Rendering page: / FAIL  Error rendering /:
Error: render function or template not defined in component: product2
    at normalizeRender (/Users/z00335s/gitdir/vuepress-test/node_modules/vue-server-renderer/build.js:7396:13)
    at renderComponentInner (/Users/z00335s/gitdir/vuepress-test/node_modules/vue-server-renderer/build.js:7520:3)
    at renderComponent (/Users/z00335s/gitdir/vuepress-test/node_modules/vue-server-renderer/build.js:7491:5)
    at resolve (/Users/z00335s/gitdir/vuepress-test/node_modules/vue-server-renderer/build.js:7552:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

What is expected?

yarn docs:build should not fail if yarn docs:dev is not throwing any error.

What is actually happening?

When I remove following imports, in docs/.vuepress/components/product2.vue the build works.

import DatePicker from "vue2-datepicker";
Vue.component('DatePicker', DatePicker)

Other relevant information

ulivz commented 6 years ago

Duplicate of #451, please step over there to see the workaround.

nikhilkul commented 6 years ago

@ulivz #451 says add code to lib/app/app.js. Does that mean I have to create a new .js file somewhere? Tried docs/.vuepress/enhanceApp.js as was mentioned in #443 , but it throws ReferenceError: window is not defined

Simply changing import DatePicker from 'vue2-datepicker'; to import DatePicker from '../../../node_modules/vue2-datepicker; in the reproduction repository mentioned above does not solve the issue. The library that I am trying to import, does not have a .vue file at root path. The folder structure looks like this,

node_modules/vue2-datepicker
├── CHANGELOG.md
├── LICENSE
├── README.md
├── README.zh-CN.md
├── lib
│   ├── datepicker.css
│   ├── datepicker.js
│   └── index.js
├── package.json
└── src
    ├── calendar.vue
    ├── directives
    │   └── clickoutside.js
    ├── index.js
    ├── index.scss
    ├── index.vue
    ├── locale
    │   └── languages.js
    ├── mixins
    │   └── locale.js
    ├── panel
    │   ├── date.js
    │   ├── month.js
    │   ├── time.js
    │   └── year.js
    └── utils
        ├── index.js
        └── scroll-into-view.js

I tried following:

  1. import DatePicker from '../../../node_modules/vue2-datepicker/src/index.vue;
  2. import DatePicker from '../../../node_modules/vue2-datepicker

Both didn't work.

nikhilkul commented 6 years ago

@ulivz Can you please help me for this ⏫