vuepress / vuepress-community

:bulb: Community supported ecosystem for VuePress
https://vuepress-community.netlify.app
MIT License
81 stars 62 forks source link

[Bug Report]For vuepress-plugin-typescript, it can't find module of typescript component #3

Closed TerryChenUI closed 4 years ago

TerryChenUI commented 4 years ago

Environment

Describe the bug

when use vuepress-plugin-typescript, I import a typescript component, it will show error of not find.

Steps To Reproduce

  1. config.js
    const pkg = require('../../package.json')
    module.exports = {
    title: pkg.name,
    description: pkg.description,
    base: '/',
    themeConfig: {
    nav: [
      { text: '组件', link: '/component/select-tree' }
    ],
    sidebar: {
      '/component/': [
        {
          title: '组件',
          collapsable: false,
          children: [
            {
              title: 'SelectTree 下拉树选择器',
              path: 'select-tree',
              collapsable: false
            }
          ]
        }
      ]
    },
    sidebarDepth: 2
    },
    plugins: [
    [
      'vuepress-plugin-typescript'
    ]
    ]
    }

2.enhanceApp.ts

import { EnhanceApp } from 'vuepress-types'
import VueHighlightJS from 'vue-highlight.js'

import {
  Table,
  TableColumn
} from 'element-ui'

import SelectTree from '../../packages/select-tree' // show error

import 'highlight.js/styles/atom-one-dark.css'

const enhanceApp: EnhanceApp = ({ Vue, options, router, siteData  }) => {
  Vue.use(Table)
  Vue.use(TableColumn)
  Vue.use(VueHighlightJS, {
    languages: {
      css: require('highlight.js/lib/languages/css'),
      javascript: require('highlight.js/lib/languages/javascript'),
      vue: require('vue-highlight.js/lib/languages/vue')
    }
  })

  // packages 组件
  Vue.component('SelectTree', SelectTree)
}

export default enhanceApp

3.packages/select-tree/index.ts

import SelectTree from './src/SelectTree.vue'

(SelectTree as any).install = function (Vue: any) {
  Vue.component(SelectTree.name, SelectTree)
}

export default SelectTree
  1. I confirm '../../packages/select-tree' path is correct, and the errors:
    
    enhanceApp.ts?5ec6:2 Uncaught Error: Cannot find module '../../packages/select-tree'
    at webpackMissingModule (enhanceApp.ts?5ec6:2)
    at eval (enhanceApp.ts?5ec6:2)
    at Module../docs/.vuepress/enhanceApp.ts (app.js:921)
    at __webpack_require__ (app.js:770)
    at fn (app.js:130)
    at eval (2.js?576c:1)
    at Module../node_modules/@vuepress/core/.temp/app-enhancers/2.js (app.js:957)
    at __webpack_require__ (app.js:770)
    at fn (app.js:130)
    at eval (app-enhancers.js?110a:1)

client?a3cb:150 [WDS] Errors while compiling. Reload prevented. errors @ client?a3cb:150 eval @ socket.js?b019:47 sock.onmessage @ SockJSClient.js?b9e5:63 EventTarget.dispatchEvent @ sockjs.js?9be2:170 eval @ sockjs.js?9be2:888 SockJS._transportMessage @ sockjs.js?9be2:886 EventEmitter.emit @ sockjs.js?9be2:86 WebSocketTransport.ws.onmessage @ sockjs.js?9be2:2962 client?a3cb:159 ./docs/.vuepress/enhanceApp.ts Module not found: Error: Can't resolve '../../packages/select-tree' in 'E:\quick\packages\admin-component\docs.vuepress'

meteorlxy commented 4 years ago

Forgot to add .ts to resolve.extensions of webpack config.

Will be fixed in next release. Currently you can use import SelectTree from '../../packages/select-tree/index.ts' instead.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.