2015-09-21 79 views
0

我繼承的角度開發出一種半完成的項目(APP)/帆/ PostgreSQL的Sails.js - Node.js的 - [的ReferenceError:承諾沒有定義]

我有棱有角,帆沒有以往的經驗.js或PostgreSQL

該應用程序在實時運行,並且正在運行,並且一些重要的用戶正在使用它。

這個程序根本沒有運行,直到我做了'mkdir logs',然後'ReferenceError:Promise沒有定義',所以我認爲這個應用程序可能是在live/configured上開發的生活。

我建立了一個本地開發環境,並且看到這個'ReferenceError'錯誤。

我懷疑配置問題是這個問題的原因,但是我不知道我錯過了什麼,如果是這樣的話。

我已經嘗試過各種命令,比如'npm install','npm update'和降級各種軟件包,目前的代碼,package.json等是活的確切副本,模塊應該是確切的相同的版本。

我可以創建一個新的帆船項目,並且在瀏覽器中查看時一切正常。

外殼輸出的解除:

[email protected]:~/dev/project$ sails lift 

info: Starting app... 

    i18n:debug will write to /home/vagrant/dev/project/config/locales/en.json +0ms 
    i18n:debug read /home/vagrant/dev/project/config/locales/en.json for locale: en +0ms 
    i18n:debug will write to /home/vagrant/dev/project/config/locales/es.json +1ms 
    i18n:debug read /home/vagrant/dev/project/config/locales/es.json for locale: es +1ms 
    i18n:debug will write to /home/vagrant/dev/project/config/locales/fr.json +0ms 
    i18n:debug read /home/vagrant/dev/project/config/locales/fr.json for locale: fr +1ms 
    i18n:debug will write to /home/vagrant/dev/project/config/locales/de.json +0ms 
    i18n:debug read /home/vagrant/dev/project/config/locales/de.json for locale: de +0ms 
[ReferenceError: Promise is not defined] 
undefined 
Unhandled rejection TypeError: Cannot read property 'message' of undefined 
    at /home/vagrant/dev/project/api/controllers/AuthController.js:23:34 
    at Strategy.strategy.error (/home/vagrant/dev/project/node_modules/passport/lib/middleware/authenticate.js:333:18) 
    at verified (/home/vagrant/dev/project/node_modules/passport-local/lib/strategy.js:81:28) 
    at /home/vagrant/dev/project/config/passport.js:79:20 
    at tryCatcher (/home/vagrant/dev/project/node_modules/bluebird/js/main/util.js:26:23) 
    at Promise._settlePromiseFromHandler (/home/vagrant/dev/project/node_modules/bluebird/js/main/promise.js:507:31) 
    at Promise._settlePromiseAt (/home/vagrant/dev/project/node_modules/bluebird/js/main/promise.js:581:18) 
    at Promise._settlePromises (/home/vagrant/dev/project/node_modules/bluebird/js/main/promise.js:697:14) 
    at Async._drainQueue (/home/vagrant/dev/project/node_modules/bluebird/js/main/async.js:123:16) 
    at Async._drainQueues (/home/vagrant/dev/project/node_modules/bluebird/js/main/async.js:133:10) 
    at Async.drainQueues (/home/vagrant/dev/project/node_modules/bluebird/js/main/async.js:15:14) 
    at process._tickDomainCallback (node.js:463:13) 

的package.json:

{ 
    "name": "project", 
    "private": true, 
    "version": "0.0.0", 
    "description": "a Sails application", 
    "keywords": [], 
    "dependencies": { 
    "ap": "^0.2.0", 
    "async": "^1.4.2", 
    "bcrypt": "~0.8.0", 
    "bluebird": "^2.10.0", 
    "crypto": "0.0.3", 
    "ejs": "~0.8.4", 
    "email-templates": "^2.0.1", 
    "forever": "^0.15.1", 
    "grunt": "0.4.2", 
    "grunt-contrib-clean": "~0.5.0", 
    "grunt-contrib-coffee": "~0.10.1", 
    "grunt-contrib-concat": "~0.3.0", 
    "grunt-contrib-copy": "~0.5.0", 
    "grunt-contrib-cssmin": "~0.9.0", 
    "grunt-contrib-jst": "~0.6.0", 
    "grunt-contrib-less": "0.11.1", 
    "grunt-contrib-uglify": "~0.4.0", 
    "grunt-contrib-watch": "~0.5.3", 
    "grunt-sails-linker": "~0.9.5", 
    "grunt-sync": "~0.0.4", 
    "html-pdf": "^1.4.0", 
    "include-all": "~0.1.3", 
    "less": "^2.5.1", 
    "mandrill-api": "^1.0.45", 
    "moment": "^2.10.6", 
    "passport": "~0.2.1", 
    "passport-local": "~1.0.0", 
    "postgres-array": "^1.0.0", 
    "postgres-bytea": "^1.0.0", 
    "postgres-date": "^1.0.0", 
    "rc": "~0.5.0", 
    "request": "^2.62.0", 
    "sails": "~0.11.0", 
    "sails-disk": "~0.10.0", 
    "sails-postgresql": "^0.10.16", 
    "sp": "^0.1.3", 
    "waterline": "^0.10.26", 
    "winston": "^1.0.1" 
    }, 
    "scripts": { 
    "start": "node app.js", 
    "debug": "node debug app.js" 
    }, 
    "main": "app.js", 
    "repository": { 
    "type": "git", 
    "url": "git://github.com/**.....**/project.git" 
    }, 
    "author": "**.....**", 
    "license": "" 
} 

API /控制器/ AuthController.js:

/** 
* AuthController 
* 
* @description :: Server-side logic for managing auths 
* @help  :: See http://links.sailsjs.org/docs/controllers 
*/ 

var passport = require('passport'); 
var bcrypt = require('bcrypt'); 

module.exports = { 
    _config: { 
     actions: false, 
     shortcuts: false, 
     rest: false 
    }, 
    login: function(req, res) { 
     passport.authenticate('local', function(err, user, info) { 
      console.log(err); 
      console.log(user); 
      if ((err) || (!user)) { 
       return res.send({ 
        message: info.message, 
        user: user 
       }); 
      } else { 
       req.logIn(user, function (err) { 
        if (err) res.send(err); 
        return res.send({ 
         message: info.message, 
         user: user 
        }); 
       }); 
      } 
     })(req, res); 
    }, 
    logout: function(req, res) { 
     req.logout(); 
     res.redirect('/'); 
    } 
}; 

我真的很感激上的一些幫助這個。

回答

1

info不是passport.authenticate行上的對象。

passport.authenticate('local', function(err, user, info) { 

您登錄erruser但你沒有登錄info - 有你登錄info,你會看到undefined,所以你不能使用它的message財產在這條線:

return res.send({ 
    message: info.message, 
    user: user 
}); 
相關問題