2016-05-09 52 views
0

私は、角型のフルスタックジェネレータを使用しています。私は何を変更したのかわかりませんが、今は私のサーバータスクがこのエラーによって停止しています。ここでTypeError:未定義の 'session'プロパティを読み取ることができません

/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) 

は(セッションを({})app.useまでの私のexpress.jsです:

/** 
* 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.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') || {})}; 

UPDATE: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.

+0

エラーはかなり明確ですか? 'environment2.default'には' secrets'というプロパティはありませんので、設定されていると思われる場所を見つけ、それが正しく起こっていない理由を見つけてください。例えば、あなたは '_.merge'の疑いがあるはずです。おそらくあなたが思っていることをしていないでしょう。 –

+0

@ Mike'Pomax'Kamermansエラーの内容を理解していますが、解決方法はわかりません。私はファイル、フォルダ、変数などを持っていません。名前はenvironment2.defaultです。私の唯一の解決策は、index.jsの秘密を環境変数にすることです。それで十分だろうと思いますか? –

+0

ここには何も変更されていませんが、今日の朝は一見 "すべてが突然"このエラーが発生しています。 –

答えて

0

解決策はここにあります:Syntax Error in Index.js。型エラーは、基礎となる構文エラーのために発生しました。

関連する問題