我是 NodeJS 的新手,并试图在 Express3.0 上构建一个应用程序,包括用于身份验证的护照本地策略。但是以下异常(关于 req.flash)阻碍了我的进步。
异常发生在以下行。 res.render('login', { user: req.user, message: req.flash('error') });
表达 500 TypeError: Object # has no method 'flash' 在 /Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/app.js:115:54 在回调(/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:162:37) 在参数(/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:136:11) 通过(/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:143:5) 在 Router._dispatch (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:171:5) 在 Object.router (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:33:10) 在下一个(/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/node_modules/connect/lib/proto.js:190:15) 在 store.get.next (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/node_modules/connect/lib/middleware/session.js:310:9) 在 /Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/node_modules/connect/lib/middleware/session.js:333:9 在 /Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/node_modules/connect/lib/middleware/session/memory.js:52:9
我已经按照作者的建议(passport-local-strategy)安装了 connect-flash 来恢复已弃用的 req.flash 方法。请找到应用程序中安装的 npm 包。
├── connect-flash@0.1.0 ├── ejs@0.8.3 ├── ejs-locals@0.2.5 ├─┬ express@3.0.0 │ ├── 指挥官@0.6.1 │ ├─┬ connect@2.6.0 │ │ ├── bytes@0.1.0 │ │ ├── formidable@1.0.11 │ │ ├── pause@0.0.1 │ │ ├── qs@0.5.1 │ │ └─┬ send@0.0.4 │ │ └── mime@1.2.6 │ ├── cookie@0.0.4 │ ├── crc@0.2.0 │ ├── debug@0.7.0 │ ├── 新鲜@0.1.0 │ ├── methods@0.0.1 │ ├── mkdirp@0.3.3 │ ├── range-parser@0.0.4 │ └─┬ 发送@0.1.0 │ └── mime@1.2.6 ├─┬ 护照@0.1.12 │ └── pkginfo@0.2.3 ├─┬ passport-local@0.1.6 │ ├── 护照@0.1.12 │ └── pkginfo@0.2.3 ├─┬ socket.io@0.9.10 │ ├── policyfile@0.0.4 │ ├── redis@0.7.2 │ └─┬ socket.io-client@0.9.10 │ ├─┬ active-x-obfuscator@0.0.1 │ │ └── zeparser@0.0.5 │ ├── uglify-js@1.2.5 │ ├─┬ ws@0.4.22 │ │ ├── 指挥官@0.6.1 │ │ ├── options@0.0.3 │ │ └── tinycolor@0.0.1 │ └── xmlhttprequest@1.4.2 └─┬ stylus@0.30.1 ├── cssom@0.2.5 ├── 调试@0.7.0 └── mkdirp@0.3.4