Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

angularjs - Syntax Error in 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') || {})};

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...