我想运行我的应用程序,突然出现此错误。为什么?
这就是我的工作顺序。
app.js:
const express = require("express");
const app = express();
/* ******** Database Connection ********* */
var db = require("./db/advertiser_db");
db.sequelize.sync().then(() => {
console.log("Database connection successfull");
app.listen(process.env.PORT, () => {
console.log("Express listening on " + process.env.PORT);
})
});
db / advertiser_db.js:
require("dotenv").config();
const Sequelize = require("sequelize");
const sequelize = new Sequelize(`${process.env.DB_NAME}`, `${process.env.DB_USERNAME}`, `${process.env.DB_PW}`, {
host: `${process.env.DB_HOST}`,
dialect: "postgres"
});
const db = {};
db.n_advertiser = sequelize.import(__dirname + "/models/advertiser/advertiser_info.js");
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
models / advertiser / advertiser_info.js:
module.exports = (sequelize, Sequelize) => {
return sequelize.define("advertiser", {
blabla: {
type: Sequelize.STRING,
allowNull: false,
},
blabla: {
type: Sequelize.STRING,
allowNull: false,
},
email: {
type: Sequelize.STRING,
allowNull: false,
validate: {
isEmail: true
}
},
hashedPw: {
type: Sequelize.STRING,
allowNull: false
},
blabla: {
type: Sequelize.STRING,
allowNull: false,
},
blabla: {
type: Sequelize.STRING,
allowNull: false
},
blabla: {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: true,
}
})
}
如果我运行app.js文件,则会看到以下错误:
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module '/Users/yildirim/Desktop/nn_backend/db/models/advertiser/advertiser_info.js'
Require stack:
- /Users/yildirim/Desktop/nn_backend/node_modules/sequelize/lib/sequelize.js
- /Users/yildirim/Desktop/nn_backend/node_modules/sequelize/index.js
- /Users/yildirim/Desktop/nn_backend/db/advertiser_db.js
- /Users/yildirim/Desktop/nn_backend/app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Sequelize.import (/Users/yildirim/Desktop/nn_backend/node_modules/sequelize/lib/sequelize.js:481:62)
at Object.<anonymous> (/Users/yildirim/Desktop/nn_backend/db/advertiser_db.js:10:40)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/yildirim/Desktop/nn_backend/app.js:5:10)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/yildirim/Desktop/nn_backend/node_modules/sequelize/lib/sequelize.js',
'/Users/yildirim/Desktop/nn_backend/node_modules/sequelize/index.js',
'/Users/yildirim/Desktop/nn_backend/db/advertiser_db.js',
'/Users/yildirim/Desktop/nn_backend/app.js'
]
}
我看到它向我展示了一条根本不存在的路径。为什么?我从未定义过该路径: '/Users/yildirim/Desktop/nn_backend/db/models/advertiser/advertiser_info.js'
感谢您的有用回答。
答案 0 :(得分:0)
尝试再次从原始文件夹中打开文件。更改位置后,我现在遇到了相同的问题。