# happening for db:create and db:migrate
$ node_modules/.bin/sequelize db:migrate
Sequelize CLI [Node: 8.9.1, CLI: 4.0.0, ORM: 4.37.4]
ERROR: Error reading "config/database.js". Error: SyntaxError: Unexpected token :
sequelize db:create respecting database.js configurationsequelize db:migrate respecting database.js configurationdb:create and db:migrate commands are unable to read config/database.js configurations. It is giving syntax error.
Sequelize CLI [Node: 8.9.1, CLI: 4.0.0, ORM: 4.37.4]
ERROR: Error reading "config/database.js". Error: SyntaxError: Unexpected token :
__Dialect:__ mysql
__Database version:__ mysql Ver 14.14 Distrib 5.7.18, for osx10.12 (x86_64) using EditLine wrapper
__Sequelize CLI version:__ 4.0.0
__Sequelize version:__ 4.37.3
Here is my .sequelizerc file
const path = require('path');
module.exports = {
'config': path.resolve('config', 'database.js'),
'models-path': path.resolve('src', 'models'),
'seeders-path': path.resolve('db', 'seeders'),
'migrations-path': path.resolve('db', 'migrations')
}
config/database.js
{
"development": {
"username": "root",
"password": null,
"database": "database_development",
"host": "127.0.0.1",
"dialect": "mysql"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
__The Problem is in config/database.js file__, as the cli is reporting syntax error, if we are using database.js to load configuration dynamically, we need to export the configurations using module.exports:
module.exports = {
"development": {
"username": "root",
"password": null,
"database": "database_development",
"host": "127.0.0.1",
"dialect": "mysql"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
Do you guys think you could update your documentation once in a while?
Most helpful comment
__The Problem is in
config/database.jsfile__, as the cli is reporting syntax error, if we are usingdatabase.jsto load configuration dynamically, we need to export the configurations usingmodule.exports:Solution: