找不到模块:内部/模块/cjs/loader.js:969
Posted
技术标签:
【中文标题】找不到模块:内部/模块/cjs/loader.js:969【英文标题】:Cannot find module: internal/modules/cjs/loader.js:969 【发布时间】:2020-10-07 17:40:35 【问题描述】:我想运行我的应用程序,但突然收到此错误。为什么?
这是我工作的订单的样子。
./
├─ app.js
├─ .env
├─ .gitignore
├─ node modules/
│ └─ ...
├─ package.json
├─ package-lock.json
├─ models/
│ └─ advertiser/
│ └─ advertiser_info.js
├─ customer
└─ db/
└─ advertiser_db.js
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;
模型/广告商/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'
感谢您的有用回答。
【问题讨论】:
你安装了 sequelize.js 吗? @RatnadeepBhattacharyya 是的,我做到了 我认为这里的问题是无法从该位置访问模块目录,请尝试使用更高的权限。 【参考方案1】:尝试从原始文件夹再次打开您的文件。更改位置后,我遇到了同样的问题。
【讨论】:
以上是关于找不到模块:内部/模块/cjs/loader.js:969的主要内容,如果未能解决你的问题,请参考以下文章
npm 没有启动。错误:找不到模块“webpack-cli/bin/config-yargs”