'Cannot find module 'sequelize/types'
anyone knows why i am getting this error this is my code
"use strict";
const { DataTypes } = require("sequelize/types");
module.exports = {
up: async (queryInterface, DataTypes) => {
await queryInterface.createTable("dummytables", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER,
},
id: {
type: DataTypes.NUMBER,
},
first_name: {
type: DataTypes.STRING,
allowNull: false,
},
last_name: {
type: DataTypes.STRING,
allowNull: false,
},
});
},
down: async (queryInterface, DataTypes) => {
await queryInterface.dropTable("dummytables");
},
};
when am trying to run this command sequelize db:migrate
and its showing me ERROR: Cannot find module 'sequelize/types'
my dependencies file
"dependencies": {
"@types/sequelize": "^4.28.9",
"express": "^4.17.1",
"mysql2": "^2.2.5",
"sequelize": "^6.5.0",
"sequelize-cli": "^6.2.0" }
any solution need help
Solution 1:[1]
If you change the second line to;
const { DataTypes } = require("sequelize");
It should work fine.
Solution 2:[2]
A better fix would be to just install Sequelize like;
const Sequelize = require("sequelize");
then use it like;
first_name: {
type: Sequelize.STRING,
allowNull: false,
},
You might not even need to do the importation because up() would give it to you for free, You just need to replace DataTypes with Sequelize.
async up(queryInterface, Sequelize) {
...
}
Solution 3:[3]
This error, may be can happen when you use auto import and it import sequelize/types, you can find in code has 'sequelize/types' and delete it in code of you should change
const {DataTypes} = require('sequelize');
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 | Bin Emmanuel |
| Solution 2 | Bin Emmanuel |
| Solution 3 | Otis |
