简体   繁体   English

无法读取未定义的属性(读取“使用”)如何在 ExpressJS 中解决此问题?

[英]Cannot read properties of undefined (reading 'use') how can I resolve this issue in ExpressJS?

The warning in the terminal is based on undefined (reading 'use')-introduced route in my app is app>router>routers.js终端中的警告基于未定义(阅读“使用”) - 在我的应用程序中引入的路由是 app>router>routers.js

const express = require("express");
const app = express();
const router = require("express").Router();
const { authRouters } = require("./Auth");
const { projectRouters } = require("./Project");
const { teamRouters } = require("./Team");
const { userRouters } = require("./User");
router.use("/project", projectRouters);
router.use("/team", teamRouters);
router.use("/user", userRouters);
router.use("/Auth", authRouters);
module.exports = { AllRouters: router };

Team.js (similarly for Project.js, Auth.js, User.js) Team.js(类似于 Project.js、Auth.js、User.js)

const router = require("express").Router();


> my codes...


module.exports = { projectRouters: router };

and finally in my Server.js最后在我的 Server.js 中

createRoutes() {
this.#app.get("/", (req, res, next) => {
  return res.json({ message: "Welcome to my app" });
});
this.#app.use((error, req, res, next) => {
  try {
    this.#app.use(AllRouters);
  } catch (error) {
    next(error);
  }
});

} }

To whom may face a similar warning: the root of the problem is a matter of not defining " AllRouters" method in the contractor of the Server.js and the solution is:谁可能会面临类似的警告:问题的根源在于没有在 Server.js 的承包商中定义“AllRouters”方法,解决方案是:

module.exports = class Application {
  #app = express();
  #PORT;
  #DB_URL;
  #AllRouters;
  constructor(PORT, DB_URL, AllRouters) {
    this.#PORT = PORT;
    this.#DB_URL = DB_URL;
    this.#AllRouters = AllRouters;
    this.ConfigApplication();
    this.ConnectToMongoDb();
    this.CreateServer();
    this.CreateRoutes();
    this.ErrorHandler();
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该如何解决这个问题? 类型错误:无法读取 react.js 中未定义(读取“地图”)的属性 - How can i solve this issue ? TypeError: Cannot read properties of undefined (reading 'map') in react.js 我该如何解决:“无法读取未定义的属性(读取'角色')” - How can I fix : "Cannot read properties of undefined( reading 'role')" TypeError:无法读取 Expressjs 中未定义的属性(读取“id”) - TypeError: Cannot read properties of undefined (reading 'id') in Expressjs TypeError:无法读取未定义的属性(读取“使用”) - TypeError: Cannot read properties of undefined (reading 'use') 我该如何解决这个错误'无法读取未定义的属性(读取'符号')'在fastify上 - How can i solve this error 'Cannot read properties of undefined (reading 'sign')' on fastify 无法读取未定义的属性(读取“行”)------我该如何解决这个问题? - Cannot read properties of undefined (reading 'rows') ------ How can I solve this problem? TypeError: Cannot read properties of undefined (reading 'strEmail') 我该如何解决这个问题? - TypeError: Cannot read properties of undefined (reading 'strEmail') How can I solve this problem? 使用带有 MySql 错误的 ExpressJS 的 CRUD 实现:无法读取未定义的属性(读取“名称”) - CRUD implementation using ExpressJS with MySql ERROR : Cannot read properties of undefined (reading 'name') “无法读取未定义的属性(读取‘0’) - "Cannot read properties of undefined (reading '0') oracledb 连接问题:无法读取未定义的属性(读取“_getConnection”) - oracledb connection issue : Cannot read properties of undefined (reading '_getConnection')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM