With ES6 modules you can not (yet?) import directories.
Here you can see I made this changes and it worked for me this are my two files below and I needed to write require to import user for it but in ES6 it doesn't support require so in my solution I created the export default of users and it comes with sequelize and datatypes values so now I created import of users above in index.js file so I can use those values without using require.
Also you have to add (.js) extension in the imported files path just like I did in index.js files second line.
Your import should look like this:
Index.js
import { DataTypes, Sequelize } from "sequelize"; **import Users from "./users.js";** const sequelize = new Sequelize("Users", "root", "", { host: "localhost", dialect: "mysql", pool: { max: 5, min: 0, idle: 10000 }, }); sequelize .authenticate() .then(() => { console.log("Connected !"); }) .catch((err) => { console.log("Error", err); }); const db = {}; db.sequelize = Sequelize; db.sequelize = sequelize; **db.users = Users(sequelize, DataTypes);** db.sequelize.sync().then(() => { console.log("YES Re-Sync !"); }); export default sequelize;
Users.js
const Users = (sequelize, DataTypes) => { sequelize.define( "Users", { name: { type: DataTypes.STRING, }, email: { type: DataTypes.STRING, defaultValue: "[email protected]", }, gender: { type: DataTypes.STRING, }, }, { // timestamps: false, // updatedAt: false, // createdAt: false, // createdAt: created_at, // updatedAt: modified_at, // engine: "Kishan", } `); }; export default Users;
import database from './database.js'don't forget .js'database/index.js'? it doesn't work.import database from './database.js'or you can useemsmodule and in your package.json just donodemon -r esm main.js