The problem is on line 2, import './database/index.js'.
Server.js
import './database/index.js'
And this is the index.js file, which is being imported into server.js.
import Sequelize from "sequelize";
import config from '../config/database';
import Model from '../models'
const models = [];
class Database {
constructor() {
this.connection = new Sequelize(config);
this.init() this.associate()
}
init() {
models.forEach((model) => model.init(this.connection))
}
associate() {
models.forEach((model) => {
if (model.associate) {
model.associate(this.connection.models);
}
})
}
}
export default new Database();
Package.json
"type": "module",
My console:
[nodemon] starting `node ./src/server.js`
node:internal/errors:491
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'D:\Nebula\Templates\Sistema Admin\src\config\database' imported from D:\Nebula\Templates\Sistema Admin\src\database\index.js
at new NodeError (node:internal/errors:400:5)
at finalizeResolution (node:internal/modules/esm/resolve:326:11)
at moduleResolve (node:internal/modules/esm/resolve:945:10)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:842:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v18.13.0
I'm try alterate a type in package.json, but continue error I believe that the problem is in the way that index.js is being exported, but I don't know another way to do that... I thought the error was due to not having the .js extension at the end of the import, but I changed it and the same thing continued.