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
copy posts.js into pages/api
run next
visit pages/api/posts
see error in console
should return 200
I wasn't able to reproduce on Windows 10 or Mac OS 10.15.1.
I followed these steps:
yarn create next-app --example api-routes-micro api-routes-micro-appcd api-routes-micro-appyarn devhttp://localhost:3000/api/postsAre 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.
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...
Most helpful comment
Maybe you didn鈥檛 install micro@canary