'Error: Cannot parse config file: '" + fullFilename + "': " + e3
I just want to set environment form development,staging and production in my project of express.js
To set these environments I use module config https://www.npmjs.com/package/config
and i created file development.js in config folder
and my code is for file development.js
import db from './db';
module.exports = {
host: '0.0.0.0',
port: process.env.PORT || 5000,
secret: process.env.SECRET || 'supersecret',
db: db.development,
base_url: process.env.BASEURL || 'http://192.168.1.153:5000',
fornt_url: process.env.FRONT_BASEURL || 'http://localhost:4200/#',
savePath:"./uploads/"
};
and i also update my package.json file in script as
"scripts": {
"test": "node app.js",
"development": "NODE_ENV=development nodemon app.js",
"staging": "NODE_ENV=staging node app.js",
"production": "NODE_ENV=production node app.js"
},
and when i run my project i got following error, please help to resolve this
[nodemon] starting `node app.js`
/data/node/tempfu-api/node_modules/config/lib/config.js:963
throw new Error("Cannot parse config file: '" + fullFilename + "': " + e3);
^
Error: Cannot parse config file: '/data/node/tempfu-api/config/development.js': SyntaxError: Unexpected token import
at Config.util.parseFile (/data/node/tempfu-api/node_modules/config/lib/config.js:963:11)
at /data/node/tempfu-api/node_modules/config/lib/config.js:725:28
at Array.forEach (<anonymous>)
at /data/node/tempfu-api/node_modules/config/lib/config.js:721:14
at Array.forEach (<anonymous>)
at Config.util.loadFileConfigs (/data/node/tempfu-api/node_modules/config/lib/config.js:720:13)
at new Config (/data/node/tempfu-api/node_modules/config/lib/config.js:136:27)
at Object.<anonymous> (/data/node/tempfu-api/node_modules/config/lib/config.js:1797:31)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/data/node/tempfu-api/helpers/mysql.js:1:78)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
Solution 1:[1]
I had this exact same issue on a different project. It was solved by removing the last trailing comma.
So if any objects in your .json files have trailing commas, you should remove them and it will load properly. This error will also pop up if you have a trailing comma inside of the object.
{...},
"sampleScript": {
"test": "node app.js",
"development": "NODE_ENV=development nodemon app.js",
"staging": "NODE_ENV=staging node app.js",
"production": "NODE_ENV=production node app.js" // No trailing comma here at the last line
} // No trailing comma here if the end of the file
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Devin Michael Gray |