TypeError:无法读取属性' session'未定义的

时间:2016-05-09 17:49:24

标签: javascript angularjs express

我正在使用角度 - fullstack发生器,一切都运行顺利到现在为止。我不知道我改变了什么,但现在我的服务器任务因此错误而停止。

/Users/User/APP/server/config/express.js:28
secret: _environment2.default.secrets.session,
                                     ^
TypeError: Cannot read property 'session' of undefined
at Object.exports.default (express.js:41:13)
at Object.<anonymous> (app.js:23:1)
at Module._compile (module.js:541:32)
at loader (/Users/User/APP/node_modules/babel-register/lib/node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/User/APP/node_modules/babel-register/lib/node.js:168:7)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/User/APP/server/index.js:12:28)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)

这是我的express.js到app.use(session({}):

/**
* Express configuration
*/

'use strict';

import express from 'express';
import favicon from 'serve-favicon';
import morgan from 'morgan';
import compression from 'compression';
import bodyParser from 'body-parser';
import methodOverride from 'method-override';
import cookieParser from 'cookie-parser';
import errorHandler from 'errorhandler';
import path from 'path';
import lusca from 'lusca';
import config from './environment';
import passport from 'passport';
import session from 'express-session';
import sqldb from '../sqldb';
import expressSequelizeSession from 'express-sequelize-session';
var Store = expressSequelizeSession(session.Store);

export default function(app) {
var env = app.get('env');

app.set('views', config.root + '/server/views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(compression());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(cookieParser());
app.use(passport.initialize());
// Persist sessions with MongoStore / sequelizeStore
// We need to enable sessions for passport-twitter because it's an
// oauth 1.0 strategy, and Lusca depends on sessions
app.use(session({
secret: config.secrets.session,
saveUninitialized: true,
resave: false,
store: new Store(sqldb.sequelize)
}));

这是我对index / environment的index.js:

'use strict';

var path = require('path');
var _ = require('lodash');

function requiredProcessEnv(name) {
if (!process.env[name]) {
throw new Error('You must set the ' + name + ' environment variable');
}
return process.env[name];
}

// All configurations will extend these options
// ============================================
var all = {
env: process.env.NODE_ENV,

// Root path of server
root: path.normalize(__dirname + '/../../..'),

// Server port
port: process.env.PORT || 9000,

// Server IP
ip: process.env.IP || '0.0.0.0',

// Should we populate the DB with sample data?
seedDB: false,

// Secret for session, you will want to change this and make it an  environment variable
secrets: {
session: process.env.session || "wav"
},
// Export the config object based on the NODE_ENV
// ==============================================
module:exports = _.merge(
all,
require('./shared'),
require('./' + process.env.NODE_ENV + '.js') || {})};

更新:增加了  在index.js的最后一行var config = _.merge(...); console.log(config); module.exports = config;,错误现在在语法中被认为是。错误:
    line 39 col 7 Expected ':' and instead saw '.'. line 42 col 3 Unexpected 'var'. line 42 col 3 Expected an identifier and instead saw 'var'. line 42 col 7 Expected ')' and instead saw 'config'. line 42 col 14 Bad assignment. line 42 col 27 Expected an identifier and instead saw ')'. line 42 col 27 Expected an identifier and instead saw ')'. line 42 col 28 Expected ')' and instead saw '; line 42 col 30 Expected '}' to match '{' from line 15 and instead saw 'console'. line 42 col 42 'config' is not defined. line 42 col 68 'config' is not defined.

1 个答案:

答案 0 :(得分:0)

此处找到并讨论了解决方案:Syntax Error in Index.js。类型错误是由基础语法错误引起的。