Next.js: api-routes-micro example fails with error

Created on 6 Dec 2019  路  6Comments  路  Source: vercel/next.js

Bug report

Describe the bug

following this example fails with error TypeError: resolver is not a function
https://github.com/zeit/next.js/blob/master/examples/api-routes-micro/pages/api/posts.js

To Reproduce

copy posts.js into pages/api
run next
visit pages/api/posts
see error in console

Expected behavior

should return 200

System information

  • OS: Windows 10
  • Browser (if applies) [e.g. chrome, safari]
  • Version of Next.js: 9.1.4

    Additional context

please add a complete reproduction

Most helpful comment

Maybe you didn鈥檛 install micro@canary

All 6 comments

I wasn't able to reproduce on Windows 10 or Mac OS 10.15.1.

I followed these steps:

  1. yarn create next-app --example api-routes-micro api-routes-micro-app
  2. cd api-routes-micro-app
  3. yarn dev
  4. Navigate to http://localhost:3000/api/posts
  5. 200 response with JSON returned

Are these the same steps as you performed? I ask just to ensure I am trying to reproduce correctly. I see you said "copy posts.js into pages/api" so I wasn't sure if you had another project you had copied that file into.

I was trying to use this example in my own existing project. Looking at the example it looks like the only thing that should be needed is to export micro from my api file but i get the error whenever I do that.

  1. copy posts.js into pages/api/test.js
  2. run next
  3. visit /api/posts in browser
  4. see error in console

is there any other requirement for using micro than returning it from an api route?

pulbic/api/test.js

import micro from 'micro';

const posts = [
    {
        title: 'Next.js is awesome',
    },
    {
        title: 'API support is really great',
    },
];

export default micro((req, res) => {
    res.status(200).json(posts);
});

error

TypeError: resolver is not a function
    at Object.apiResolver (C:\Users\steph\PhpstormProjects\auth-proxy\node_modules\next\dist\next-server\server\api-utils.js:39:9)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async DevServer.handleApiRequest (C:\Users\steph\PhpstormProjects\auth-proxy\node_modules\next\dist\next-server\server\next-server.js:356:9)
    at async Object.fn (C:\Users\steph\PhpstormProjects\auth-proxy\node_modules\next\dist\next-server\server\next-server.js:283:21)
    at async Router.execute (C:\Users\steph\PhpstormProjects\auth-proxy\node_modules\next\dist\next-server\server\router.js:25:32)
    at async DevServer.run (C:\Users\steph\PhpstormProjects\auth-proxy\node_modules\next\dist\next-server\server\next-server.js:406:29)

Maybe you didn鈥檛 install micro@canary

I have 9.3.4 installed. does it have to be the canary?

Yep, installed canary and it works. why has that canary not been released since Jul 22, I think the poor birds have had all the time then needed to to squawk warning...

Was this page helpful?
0 / 5 - 0 ratings