0
'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') || {})}; 

Когда бежал с моим проектом (веб-приложение создано с угловым-fullstack), я получаю следующее сообщение об ошибке:Ошибка синтаксиса в index.js

Line 39 col 6 Unexpected token: module.exports 
             ^
line 39 col 7 Expected ':' and instead saw '.'. 
    line 42 col 54 Expected '}' to match '{' from line 15 and instead saw ';'. 

Кроме того, этот код здесь также вызвало у меня какой-то другой проблемы в моем проекте. Я изменил последние несколько строк на:

var config = _.merge(...); 
    console.log(config); 
    module.exports = config;` 
And I still get a syntax error: ` line 39 col 7 Expected ':' and instead saw 'config'. 
    line 39 col 14 Expected an identifier and instead saw '='. 
    line 39 col 16 Expected '}' to match '{' from line 15 and instead saw '_'. 
    line 39 col 27 Expected an identifier and instead saw ')'. 
    line 39 col 27 Expected an identifier and instead saw ')'. 
    line 39 col 28 Expected ')' and instead saw ';'. 
    line 40 col 15 'config' is not defined. 
    line 41 col 20 'config' is not defined. 

ответ

0

'module.export' внутри 'все' объект, перемещая его снаружи должно работать:

'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') || {} 
); 
+0

Спасибо, я заметил такую ​​маленькую вещь. я ценю это –

0

Пожалуйста, научитесь правильно вставлять свой код. Ваша ошибка должна быть кристально чистой, чтобы найти.

Coding Style Guide for node.js apps?

https://github.com/felixge/node-style-guide

+0

Спасибо, я прошу прощения за свою ошибку. –

+0

np, отступьте его, затем, если вы снова не сработаете, отправьте сообщение, чтобы узнать, можем ли мы помочь. –

 Смежные вопросы

  • Нет связанных вопросов^_^