admin管理员组

文章数量:1427755

I am trying to create a config file in js for all my keys. The problem is that i am not able to export and export the file. Here is the code and the error:

config.js:

export const mailchimpKey ='KEY'

app.js:

//jshint esversion: 6
const config = require('./config');

I have the folowing error when starting my node server:

C:\Code\boootstrap\boootstrap\src\newsletter\config.js:1
(function (exports, require, module, __filename, __dirname) { export const mailchimpKey ='KEY'
                                                          ^^^^^^

SyntaxError: Unexpected token export
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._pile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
[nodemon] app crashed - waiting for file changes before starting...

I read somewhere that I need babel set up to use import/export. Is that true? I tried installing this but not sure I set it up well

I am trying to create a config file in js for all my keys. The problem is that i am not able to export and export the file. Here is the code and the error:

config.js:

export const mailchimpKey ='KEY'

app.js:

//jshint esversion: 6
const config = require('./config');

I have the folowing error when starting my node server:

C:\Code\boootstrap\boootstrap\src\newsletter\config.js:1
(function (exports, require, module, __filename, __dirname) { export const mailchimpKey ='KEY'
                                                          ^^^^^^

SyntaxError: Unexpected token export
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._pile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
[nodemon] app crashed - waiting for file changes before starting...

I read somewhere that I need babel set up to use import/export. Is that true? I tried installing this but not sure I set it up well

Share Improve this question asked Jun 6, 2019 at 11:15 labellelabelle 4505 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Can you try this:

module.exports={
   mailchimpKey:'KEY'

}

Instead of your code in config.js

本文标签: javascriptImport configjs file in another fileStack Overflow