Koa-Cookie throwing "cookie is not a function"

Viewed 32

I am trying to follow the instructions here, and my code looks like this...

import Koa from "koa";
import cookie from "koa-cookie";

const port = process.env.PORT || 8000
const app = new Koa();
app.use(cookie());

But when I try running I get...

TypeError: cookie is not a function

1 Answers

Have you tried importing like this?

import * as cookie from "koa-cookie";

This one below worked for me therefore above example should work too

const Koa = require("koa");
const {default: cookie} = require("koa-cookie");

const port = process.env.PORT || 8000
const app = new Koa();
app.use(cookie());
app.listen(port);
Related