类型错误:无法读取未定义的 React Express 的属性“原型" [英] TypeError: Cannot read property 'prototype' of undefined React Express
问题描述
我有一个项目使用 Express 和 react,一切正常,
I have a project uses Express and react, Everything was working fine,
我没有对代码进行任何更改突然开始出现此错误.
I didn't make any changes to the code suddenly it starts to give this error.
前几天把node从10.15.0升级到12.x,加了Axios.
In the previous days, I have upgraded node from 10.15.0 to 12.x and added Axios.
我在这些更改后进行了测试,并且可以正常工作.现在没有了,这是什么意思??
I tested after those changes and it works. now it does not, what this mean??
TypeError: Cannot read property 'prototype' of undefined
(anonymous function)
C:/Desktop/ahmad/client/node_modules/express/lib/response.js:42
39 | * @public
40 | */
41 |
> 42 | var res = Object.create(http.ServerResponse.prototype)
43 |
44 | /**
45 | * Module exports.
*/
View compiled
./node_modules/express/lib/response.js
http://localhost:3000/static/js/bundle.js:28181:30
__webpack_require__
C:/.../ahmad/client/webpack/bootstrap 4501180ca3adc0d915c0:678
675 | };
676 |
677 | // Execute the module function
> 678 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
679 |
680 | // Flag the module as loaded
681 | module.l = true;
View compiled
fn
C:/.../ahmad/client/webpack/bootstrap 4501180ca3adc0d915c0:88
85 | console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
86 | hotCurrentParents = [];
87 | }
> 88 | return __webpack_require__(request);
89 | };
90 | var ObjectFactory = function ObjectFactory(name) {
91 | return {
View compiled
./node_modules/express/lib/express.js
C:/.../Desktop/ahmad/client/node_modules/express/lib/express.js:22
19 | var Route = require('./router/route');
20 | var Router = require('./router');
21 | var req = require('./request');
> 22 | var res = require('./response');
23 |
24 | /**
25 | * Expose `createApplication()`.
*/
View compiled
__webpack_require__
C:/.../Desktop/ahmad/client/webpack/bootstrap 4501180ca3adc0d915c0:678
675 | };
676 |
677 | // Execute the module function
> 678 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
679 |
680 | // Flag the module as loaded
681 | module.l = true;
View compiled
fn
C:/.../Desktop/ahmad/client/webpack/bootstrap 4501180ca3adc0d915c0:88
85 | console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
86 | hotCurrentParents = [];
87 | }
> 88 | return __webpack_require__(request);
89 | };
90 | var ObjectFactory = function ObjectFactory(name) {
91 | return {
View compiled
推荐答案
我发现我打错了
从 { 'express' } 导入响应
我发现当您尝试在前端调用后端内容时会发生此问题.当我删除那行问题解决了.
I found that this problem happens when you try to call backEnd stuff in your frontEnd. when I delete that line problem solved.
原来我没有输入import语句,因为我使用了response
这个词作为变量名,它是自动导入的.我不确定导入是来自 React 本身还是其他 VS 代码自动完成扩展.
it turns out that I didn't type the import statement because I used the word response
as a variable name, it was automatically imported.
I'm not sure if the import was from React itself or another VS code auto-completion extension.
这篇关于类型错误:无法读取未定义的 React Express 的属性“原型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!