koajs / csrf

CSRF tokens for koa
MIT License
264 stars 32 forks source link

CSRF is not a constructor #38

Closed mchavezi closed 7 years ago

mchavezi commented 7 years ago

I cloned this repo: https://github.com/mapmeld/koa-passport-example and getting this crucial error:

/usr/src/app/server.js:36
app.use(new CSRF({
        ^

TypeError: CSRF is not a constructor
    at Object.<anonymous> (/usr/src/app/server.js:36:9)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3
[nodemon] app crashed - waiting for file changes before starting...

I am running inside docker containers using docker-compose and the mac client.

I am not sure how to solve.

mchavezi commented 7 years ago

Removing default from const CSRF = require('koa-csrf').default solved the error.

stephenmathieson commented 7 years ago

We're now exporting via module.exports, so you no longer need to grab .default. Sorry for the confusion!

EDIT: For anyone following - this does not change the behavior when using import with a transpiler (Babel).