I was using sequelize-cli to create postgresql DB using the command:
npx sequelize-cli db:create.
My config.js file is
const dotenv = require('dotenv')
dotenv.config()
module.exports = {
development: {
username: process.env.PG_USER,
password: process.env.PG_PASS,
database: process.env.PG_DB,
host: process.env.PG_HOST,
dialect: 'postgres',
}
}
I was getting the below error
TypeError: Cannot read properties of undefined (reading 'replace')
at Object.removeTicks (/../node_modules/sequelize/lib/utils.js:281:12)
at PostgresQueryGenerator.quoteIdentifier [as _quoteIdentifier] (/../node_modules/sequelize/lib/dialects/postgres/query-generator.js:663:33)
at PostgresQueryGenerator.quoteIdentifier (/../node_modules/sequelize/lib/dialects/abstract/query-generator.js:696:19)
at getCreateDatabaseQuery (/../node_modules/sequelize-cli/lib/commands/database.js:60:50)
at exports.handler (/../node_modules/sequelize-cli/lib/commands/database.js:37:17)
I figured out, the
.envfile was not loaded properly fromdotenv.config()due to path issue as.envwas in different directory. That's why I got the error. I solved it by setting path like this in config.js file.So, if you face similar issue, specify your
.envpath.