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

TypeError: utils.compose(...)(...).then is not a function #10

Closed
apiep opened this issue Oct 22, 2016 · 9 comments
Closed

TypeError: utils.compose(...)(...).then is not a function #10

apiep opened this issue Oct 22, 2016 · 9 comments

Comments

@apiep
Copy link

apiep commented Oct 22, 2016

Hi, I just wanna try out koa and when I look on how to route it, I was amaze by how easy the koa-rest-router are. But when I use it with koa version 1, I got this error instead.

koa version: ^1.2.4
koa-rest-router version: ^1.0.0

Error message

TypeError: utils.compose(...)(...).then is not a function
      at C:\Users\Apiep\Documents\Hacking\qiscus-vacation\node_modules\koa-better-router\index.js:544:52
      at Object.converted (C:\Users\Apiep\Documents\Hacking\qiscus-vacation\node_modules\koa-convert\index.js:48:27)
      at next (native)
      at Object.<anonymous> (C:\Users\Apiep\Documents\Hacking\qiscus-vacation\node_modules\koa-compose\index.js:28:19)
      at next (native)
      at onFulfilled (C:\Users\Apiep\Documents\Hacking\qiscus-vacation\node_modules\co\index.js:65:19)
      at C:\Users\Apiep\Documents\Hacking\qiscus-vacation\node_modules\co\index.js:54:5
      at Object.co (C:\Users\Apiep\Documents\Hacking\qiscus-vacation\node_modules\co\index.js:50:10)
      at Object.createPromise (C:\Users\Apiep\Documents\Hacking\qiscus-vacation\node_modules\co\index.js:30:15)
      at Server.handleRequest (C:\Users\Apiep\Documents\Hacking\qiscus-vacation\node_modules\koa\lib\application.js:136:8)

How I "mount" the router:
app.use(userRouter.legacyMiddleware())

How I write the router:

router.resource('users', {
  index: function * (next) {
    this.body = { name: 'index' }
  },
  new: function * (next) {
    this.body = { name: 'new' }
  }
}

If you want to look the whole app you can check my repo: https://github.com/apiep/qiscus-vacation/blob/master/router/user.js

@tunnckoCore
Copy link
Owner

tunnckoCore commented Oct 22, 2016

Heya! Very thanks you are trying it and decided to use it! Used from day 1 of its publishing is very cool :)

Hm. Strange. I'll look what happens. Cuz I can't figure out how to install two versions of one package as devDeps... Any ideas, btw?

Thanks for reporting.

edit: in anyway, fix (if any is needed) would be done on koa-better-router.

@tunnckoCore
Copy link
Owner

tunnckoCore commented Oct 22, 2016

@apiep can you share what node version you are using? Cuz I don't have problems locally (node 6.6).

let app = require('koa')()
let router = require('./index')()

router.resource('users')

app.use(router.legacyMiddleware())

app.listen(4242, () => {
  console.log('Koa server listening on 4242')
  router.getRoutes().forEach(route => {
    console.log(route.path)
  })
})

Also, try to clean npm and yarn caches, remove/delete their dirs in user home, remove yarn.lock and node_modules. Then try to just install the deps with npm, not yarn. If it's okey, then repeat the previous steps and try with yarn.

i'll clone your repo too.

@apiep
Copy link
Author

apiep commented Oct 22, 2016

I'm using node version 6.9.1

And what is inside your ./index ? Your koa-rest-router index or your router example configuration? 😁 Cuz when I try, I cant invoke it as a function.

And sorry forgot to mention earlier, the error will appear when you access the url. The application startup is working normally and list all my url. But when I try it on postman the error shown.

@tunnckoCore
Copy link
Owner

tunnckoCore commented Oct 22, 2016

Mmmm yea. Confirmed. I think i figure it out why it is failing. I think the problem is that koa-better-router uses [email protected] (the next tag) but koa@1 uses koa-compose<3 Just realized that koa-compose is missing in koa-better-router deps, whahah.. How strange.

And what is inside your ./index ?

yea, the koa-rest-router index (the default export)

And sorry forgot to mention earlier, the error will appear when you access the url

yea, noticed that

Anyway. Partially my fault and partially npm's fault. This flatteing have its pluses, but minuses too. It installs koa-compose@<3 from koa@1 and koa-better-router resolves it instead of [email protected] - and that's why CI does not fails. Another reason is that there's no tests for koa1, cuz npm does not allows the users have two versions of one package.

Anyway. I'll push a patch in koa-better-router in a bit and it will come here automagically :) Thanks again!

edit: Ooooh, that's sweeet, we have koa2 package in npm!

@apiep
Copy link
Author

apiep commented Oct 22, 2016

cuz npm does not allows the users have two versions of one package.

Maybe adding the package as a peerDeps? Sometimes I see something like this: [email protected] || 2.x.x. But not sure if this work or not, because I never use peerDeps before.

And thanks for the support even if I just arrived at koa world 😅

@tunnckoCore
Copy link
Owner

because I never use peerDeps before.

haha, me too. I just thought to create koa2 and check it and it is already used for exact same thing, haha! Really cool.

And thanks for the support even if I just arrived at koa world

Ooooh, welcome! It's pretty cool and awesome! I have couple of more awesome koa packages starting with koa-better-* :) And some of them are ported to express too - example of this is koa-ip-filter and express-ip-filter. I'm hoping to update koa-better-ratelimit and express-better-ratelimit tonight.

Jump directly on Koa v2 then :) We have couple of days until anything lower than node@4 is dropped totally and forever.

@tunnckoCore
Copy link
Owner

tunnckoCore commented Oct 22, 2016

@apiep thanks again! [email protected] is published.

edit: I'm just publishing these routers cuz i'm thinking to create CI service, built on koa - CI service only for nodejs built on nodejs - it will be awesome!
edit2: I cloned your repo and it seems it works now with this updates :)

@apiep
Copy link
Author

apiep commented Oct 22, 2016

Your welcome man, glad this issue help your package.

Never though it gonna be fixed in just 2 hour 😀

@tunnckoCore
Copy link
Owner

Me too. Come back if more problems appear. I'm always open.

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

No branches or pull requests

2 participants