einsqing / koa-directory-router

5 stars 0 forks source link

TypeError: koa_directory_router_1.default is not a function #1

Open comeriven opened 3 years ago

comeriven commented 3 years ago
image
import * as Router from 'koa-router'
import directoryRouter from 'koa-directory-router'
import * as path from 'path'

const koaRouter = (app: any) => {
  const router = new Router()
  const user = directoryRouter({
    root: path.resolve(__dirname, path.normalize('../controller/user')),
    suffix: '.ts',
    prefix: '/user'
  })
  router.get('/', async ctx => {
    ctx.body = 'hello world!'
  })

  app.use(user.routes())
    .use(user.allowedMethods())

  app.use(router.routes())
    .use(router.allowedMethods())

  return app
}

export default koaRouter

tsc 执行之后,nodemon dist/app.js 然后就报错了

comeriven commented 3 years ago

补充一下,自己在src目录下创建typings 目录,并创建定义文件 koa-directory-router.d.ts

declare module 'koa-directory-router' {
  var content: any
  export default content
}
comeriven commented 3 years ago
{
"node": "v12.18.0",
"typescript": "^4.0.5",
"koa-directory-router": "^2.0.7",
}
comeriven commented 3 years ago

应该是import导入的问题,希望早日支持