TypeError:无法读取未定义的React Express的属性'prototype'

时间:2020-01-24 20:47:00

标签: node.js reactjs webpack axios

我有一个使用Express并反应的项目,一切正常,

我没有对代码进行任何更改,它突然开始出现此错误。

前几天,我已将节点从10.15.0升级到12.x,并添加了Axios。

这些更改之后,我进行了测试,并且可以正常工作。现在不,这意味着什么??


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

7 个答案:

答案 0 :(得分:15)

我发现我打错了

import response from { 'express' }

我发现,当您尝试在FrontEnd中调用backEnd时,会发生此问题。 当我删除该行问题时解决了。

编辑:事实证明我没有键入import语句,因为我使用单词response作为变量名,它是自动导入的。 我不确定导入是来自React本身还是另一个VS代码自动完成扩展。

答案 1 :(得分:1)

来自{'express'}的导入响应; 进口了 默认情况下,在“操作”页面中按“ vs代码”

答案 2 :(得分:1)

太好了!同样的问题,我不使用Express。当创建一个 const 请求并使用智能来完成句子时,这发生在我身上。我删除了该行

 import { request } from 'express';

自动添加,项目已经运行

答案 3 :(得分:0)

或者您可以只替换express / lib / response.js中的“ res” (用其他任何变量替换“ res”,“ responsee”对我有用) (请确保也替换导出语句中的“ res”)

答案 4 :(得分:0)

import { json } from "express" 

这可能是通过vs代码或反应自动导入的,所以只需删除它即可。

答案 5 :(得分:0)

在我处理一个文件时,此错误突然出现。然后,我检查了第一行,并显示了import e from 'express'这一行,不知道为什么。我刚刚将其删除,并且可以正常工作。

答案 6 :(得分:0)

这也发生在我身上,因为在 React 组件中使用 handleSubmit 时,我忘记在参数中添加 e(事件)并在函数内部调用了 e.preventDefault(),而 this e auto导入上面提到的内容

Here is the fix screenshot