关键词:
【中文标题】TypeError:无法读取未定义的属性“获取”(Node.js)【英文标题】:TypeError: Cannot read property 'get' of undefined (Node.js) 【发布时间】:2017-02-06 22:49:00 【问题描述】:我是 Node.js 的新手,我需要帮助。我正在尝试使用 express (^4.14.1)、路径 (^0.12.7) 和 vash (^0.12.2) Visual Studio 中的模块。我刚刚创建了几个文件,下面将向您展示。 homeController.js 和 index.js 文件位于 controllers 文件夹中。
package.json
"name": "the-board5",
"version": "0.0.0",
"description": "TheBoard5",
"main": "server.js",
"author":
"name": "Utku"
,
"dependencies":
"express": "^4.14.1",
"path": "^0.12.7",
"vash": "^0.12.2"
server.js
var http = require("http");
var express = require("express");
var app = express();
var controllers = require("./controllers");
var port = process.env.port || 1337;
app.set("view engine", "vash");
controllers.init();
http.createServer(app).listen(port);
homeController.js
(function (homeController)
homeController.init = function (app)
app.get("/", function (req, res)
res.render("index", title: "Express + Vash" );
);
;
)(module.exports);
index.js
(function (controllers)
var homeController = require("./homeController");
controllers.init = function (app)
homeController.init(app);
;
)(module.exports);
问题是我收到了这个错误。
C:\Users\Utku\documents\visual studio 2015\Projects\TheBoard5\TheBoard5\controll
ers\homeController.js:5
app.get("/", function (req, res)
^
TypeError: Cannot read property 'get' of undefined
at Object.homeController.init (C:\Users\Utku\documents\visual studio 2015\Pr
ojects\TheBoard5\TheBoard5\controllers\homeController.js:5:12)
at Object.controllers.init (C:\Users\Utku\documents\visual studio 2015\Proje
cts\TheBoard5\TheBoard5\controllers\index.js:5:24)
at Object.<anonymous> (C:\Users\Utku\documents\visual studio 2015\Projects\T
heBoard5\TheBoard5\server.js:12:13)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:420:7)
【问题讨论】:
【参考方案1】:你错过了通过app
排队
controllers.init();
应该是
controllers.init(app);
【讨论】:
未处理的拒绝(TypeError):无法读取未定义的属性“重新获取” - GraphQL
】未处理的拒绝(TypeError):无法读取未定义的属性“重新获取”-GraphQL【英文标题】:UnhandledRejection(TypeError):Cannotreadproperty\'refetch\'ofundefined-GraphQL【发布时间】:2020-06-1115:50:24【问题描述】:今天我在我的React.js项目中遇到了Gr... 查看详情
TypeError:从 API 获取时无法读取未定义的属性(读取“地图”)
】TypeError:从API获取时无法读取未定义的属性(读取“地图”)【英文标题】:TypeError:cannotreadpropertyofundefined(reading\'map\')whilefetchingfromAPI【发布时间】:2021-12-2000:12:14【问题描述】:我正在开发一个全栈博客站点项目,在该项目... 查看详情
TypeError:无法读取未定义的属性“获取”(Node.js)
】TypeError:无法读取未定义的属性“获取”(Node.js)【英文标题】:TypeError:Cannotreadproperty\'get\'ofundefined(Node.js)【发布时间】:2017-02-0622:49:00【问题描述】:我是Node.js的新手,我需要帮助。我正在尝试使用express(^4.14.1)、路径(^0.1... 查看详情
使用 Sequelize 获取“TypeError:无法读取未定义的属性‘findAll’”
】使用Sequelize获取“TypeError:无法读取未定义的属性‘findAll’”【英文标题】:Getting"TypeError:Cannotreadproperty\'findAll\'ofundefined"withSequlize【发布时间】:2019-10-2213:22:21【问题描述】:我正在使用PostgreSQL、Sequelize和Express开发... 查看详情
TypeError:无法读取未定义的属性“棱镜”
】TypeError:无法读取未定义的属性“棱镜”【英文标题】:TypeError:Cannotreadproperty\'prismic\'ofundefined【发布时间】:2020-03-1303:08:17【问题描述】:我正在使用Gatsby/GraphQL/Prismic开展一个项目。当我尝试使用GraphQL从PrismicAPI获取数据时... 查看详情
TypeError:无法读取未定义的属性“获取”(修复冲突导入不起作用)
】TypeError:无法读取未定义的属性“获取”(修复冲突导入不起作用)【英文标题】:TypeError:Cannotreadproperty\'get\'ofundefined(Fixedconflictingimportsnotworking)【发布时间】:2020-03-0709:09:17【问题描述】:尝试运行karmaTS规范文件时出错。... 查看详情
开玩笑抛出 TypeError:无法读取未定义的属性“获取”
】开玩笑抛出TypeError:无法读取未定义的属性“获取”【英文标题】:JestthrowingTypeError:Cannotreadproperty\'fetch\'ofundefined【发布时间】:2017-10-1802:48:22【问题描述】:我正在尝试使用Jest在我的react/react-native库上运行一些测试(里面... 查看详情
无法从 nextjs 中的 api 获取图像-TypeError:无法读取未定义的属性(读取“地图”)NEXTJS
】无法从nextjs中的api获取图像-TypeError:无法读取未定义的属性(读取“地图”)NEXTJS【英文标题】:can\'tfetchimagefromapiinnextjs-TypeError:Cannotreadpropertiesofundefined(reading\'map\')NEXTJS【发布时间】:2022-01-1200:31:21【问题描述】:我似乎无... 查看详情
Angular给出TypeError:“无法读取未定义的属性'id'”
】Angular给出TypeError:“无法读取未定义的属性\\\'id\\\'”【英文标题】:AngulargivingTypeError:"Cannotreadproperty\'id\'ofundefined"Angular给出TypeError:“无法读取未定义的属性\'id\'”【发布时间】:2019-08-1114:11:22【问题描述】:我正... 查看详情
VueJS 获取 TypeError:删除和添加传感器信息时无法读取未定义的属性
】VueJS获取TypeError:删除和添加传感器信息时无法读取未定义的属性【英文标题】:VueJSgettingTypeError:CannotreadpropertiesofundefinedwhenIdeleteandaddanSensorinformation【发布时间】:2021-11-1910:09:34【问题描述】:我正在尝试在我的VueJS应用程序... 查看详情
ReactJS TypeError:无法读取未定义的属性(读取“地图”)
】ReactJSTypeError:无法读取未定义的属性(读取“地图”)【英文标题】:ReactJSTypeError:Cannotreadpropertiesofundefined(reading\'map\')【发布时间】:2021-11-1718:43:36【问题描述】:我目前正在使用两个组件,并在两个组件上都实现了reactRoute... 查看详情
Discord.js:TypeError:无法读取未定义的属性“删除”
】Discord.js:TypeError:无法读取未定义的属性“删除”【英文标题】:Discord.js:TypeError:Cannotreadproperty\'remove\'ofundefined【发布时间】:2020-09-0316:40:19【问题描述】:我无法从message.mentions.roles.first()和message.mentions.members.first()获取正确... 查看详情
NextJS:TypeError:无法读取未定义的属性“json”
】NextJS:TypeError:无法读取未定义的属性“json”【英文标题】:NextJS:TypeError:Cannotreadproperty\'json\'ofundefined【发布时间】:2020-12-2805:24:36【问题描述】:我已将此代码放入NextJS环境中的pages文件夹中。它获取调用外部APIRest的数据... 查看详情
TypeError:无法读取未定义的属性(读取“拆分”)
】TypeError:无法读取未定义的属性(读取“拆分”)【英文标题】:TypeError:cannotreadpropertiesofundefined(reading\'split\')【发布时间】:2022-01-1816:06:46【问题描述】:我是Angular单元测试(Jasminekarma)的新手。我收到TypeError:cannotreadpropert... 查看详情
TypeError:尝试编辑时无法读取未定义的属性“get”
】TypeError:尝试编辑时无法读取未定义的属性“get”【英文标题】:TypeError:Cannotreadproperty\'get\'ofundefinedwhiletryingtoedit【发布时间】:2021-10-0500:18:03【问题描述】:我尝试使用以下代码获取公会:constguild=Discord.Client.guilds.get("GUILD_I... 查看详情
React - TypeError:无法读取未定义的属性“图像”
】React-TypeError:无法读取未定义的属性“图像”【英文标题】:React-TypeError:Cannotreadproperty\'image\'ofundefined【发布时间】:2021-02-1923:10:03【问题描述】:所以我正在为一个副项目创建一个电子商务商店,但我遇到了一个问题。在主... 查看详情
未处理的拒绝(TypeError):无法读取未定义的属性“映射”? (反应火力基地)
】未处理的拒绝(TypeError):无法读取未定义的属性“映射”?(反应火力基地)【英文标题】:UnhandledRejection(TypeError):Cannotreadproperty\'map\'ofundefined?(React-firebase)【发布时间】:2021-01-1209:46:57【问题描述】:我在做什么有什么问... 查看详情
TypeError:无法读取未定义的属性(读取“问题”)
】TypeError:无法读取未定义的属性(读取“问题”)【英文标题】:TypeError:Cannotreadpropertiesofundefined(reading\'ques\')【发布时间】:2022-01-0100:32:37【问题描述】:不断收到此错误TypeError:Cannotreadpropertiesofundefined(reading\'ques\')在faq.ques... 查看详情