Index.js中的语法错误 [英] Syntax Error in Index.js

查看:188
本文介绍了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') || {})};

当运行我的项目(使用angular-fullstack创建的Web应用程序)时,出现以下错误:

When ran with my project (web app created with angular-fullstack), I receive the following error :

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 ';'.

此外,这里的代码还给我的项目带来了其他一些问题.我将最后几行更改为:

Also, this code here also caused me some other problems in my project. I changed last few lines to :

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.

推荐答案

'module.export'位于'all'对象内部,将其移至外部应该可以:

'module.export' is inside 'all' object, moving it outside should work:

'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中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆