ERR_HTTP_HEADERS_SENT: Cannot set headers after they are sent to the client

前端 未结 5 522
-上瘾入骨i
-上瘾入骨i 2020-12-02 18:41

I\'m facing this weird issue in NodeJS when using with Passport.js, Express and Mongoose. Basically, I get an error saying \"Cannot set headers after they are sent to the cl

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 18:59

    you have to enable Promises in your programm, in my case i enabled it in my mongoose schema by using mongoose.Promise = global.Promise . This enables using native js promises.

    other alternatives to this soloution is :

    var mongoose = require('mongoose');
    // set Promise provider to bluebird
    mongoose.Promise = require('bluebird');
    

    and

    // q
    mongoose.Promise = require('q').Promise;
    

    but you need to install these packages first.

提交回复
热议问题