DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed

做~自己de王妃 提交于 2020-02-22 05:15:53

问题


I'm getting below error on expressJs with Sequelize

DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.

Any idea to fix this?


回答1:


This is not an error, it's simply a warning stating that passing boolean values to operatorsAliases in sequelize options will be deprecated in v5.

To remove the warning, replace the boolean value by '1' or '0' for true and false respectively.




回答2:


Package versions:

"sequelize": "^5.21.3",
"sequelize-cli": "^5.5.1"

Firstly, I created the .sequelizerc file using touch .sequelizerc command. And I changed the path for each directory. Instead of generating config/config.json file, I need to tell sequelize-cli to generate config/config.js file so that it can access environment variables. So I changed config.json to config.js.

.sequelizerc:

const path = require('path');

module.exports = {
  'config': path.resolve('src/config', 'config.js'),
  'models-path': path.resolve('src/db', 'models'),
  'seeders-path': path.resolve('src/db', 'seeders'),
  'migrations-path': path.resolve('src/db', 'migrations')
}

Then, I generated the config/config.js using npx sequelize-cli init command.

The generated config/config.js:

{
  "development": {
    "username": "root",
    "password": null,
    "database": "database_development",
    "host": "127.0.0.1",
    "dialect": "mysql",
    "operatorsAliases": false
  },
  "test": {
    "username": "root",
    "password": null,
    "database": "database_test",
    "host": "127.0.0.1",
    "dialect": "mysql",
    "operatorsAliases": false
  },
  "production": {
    "username": "root",
    "password": null,
    "database": "database_production",
    "host": "127.0.0.1",
    "dialect": "mysql",
    "operatorsAliases": false
  }
}

It's not valid commonjs module, so I change it to:

require('dotenv').config();

module.exports = {
  development: {
    username: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASSWORD,
    database: process.env.POSTGRES_DB,
    host: process.env.POSTGRES_HOST,
    port: process.env.POSTGRES_PORT,
    dialect: 'postgres',
    operatorsAliases: false,
  },
  test: {
    username: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASSWORD,
    database: process.env.POSTGRES_DB,
    host: process.env.POSTGRES_HOST,
    port: process.env.POSTGRES_PORT,
    dialect: 'postgres',
    operatorsAliases: false,
  },
  production: {
    username: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASSWORD,
    database: process.env.POSTGRES_DB,
    host: process.env.POSTGRES_HOST,
    port: process.env.POSTGRES_PORT,
    dialect: 'postgres',
    operatorsAliases: false,
  },
};

I met this issue when I ran npx sequelize-cli db:create command.

☁  node-sequelize-examples [master] ⚡  npx sequelize-cli db:create   

Sequelize CLI [Node: 10.16.0, CLI: 5.5.1, ORM: 5.21.3]

Loaded configuration file "src/config/config.js".
Using environment "development".
(node:96656) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.

As the warning says, just remove the operatorsAliases option from the config.js. The final config/config.js:

require('dotenv').config();

module.exports = {
  development: {
    username: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASSWORD,
    database: process.env.POSTGRES_DB,
    host: process.env.POSTGRES_HOST,
    port: process.env.POSTGRES_PORT,
    dialect: 'postgres',
  },
  test: {
    username: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASSWORD,
    database: process.env.POSTGRES_DB,
    host: process.env.POSTGRES_HOST,
    port: process.env.POSTGRES_PORT,
    dialect: 'postgres',
  },
  production: {
    username: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASSWORD,
    database: process.env.POSTGRES_DB,
    host: process.env.POSTGRES_HOST,
    port: process.env.POSTGRES_PORT,
    dialect: 'postgres',
  },
};

Then, run npx sequelize-cli db:create command again, the warning is gone.

☁  node-sequelize-examples [master] ⚡  npx sequelize-cli db:create

Sequelize CLI [Node: 10.16.0, CLI: 5.5.1, ORM: 5.21.3]

Loaded configuration file "src/config/config.js".
Using environment "development".
Database node-sequelize-examples created.


来源:https://stackoverflow.com/questions/58593200/deprecationwarning-a-boolean-value-was-passed-to-options-operatorsaliases-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!