TypeError: Cannot read property 'prototype' of undefined React Express

徘徊边缘 提交于 2021-02-05 04:59:41

问题


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.

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

回答1:


I found the I have mistakenly typed

import response from { 'express' }

I found that this problem happens when you try to call backEnd stuff in your frontEnd. when I delete that line problem solved.

Edit: 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.




回答2:


import response from { 'express' }; got imported in your actions page by default by "vs code"




回答3:


While im working with one file, this error suddenly appears. I was then checked the top line and this import e from 'express' line appears without knowing why. I just removed it, and it works.




回答4:


Great! the same problem, I don't use Express. It's happened to me when a create a const request and use the intelligence to complete the sentency. I removed the line

 import { request } from 'express';

which is automatically added, and the project is already running




回答5:


Or you can just replace the 'res' in express/lib/response.js (Replace 'res' with any other variable , 'responsee' worked for me) (Make sure you replace the 'res' in export statement too)




回答6:


import { json } from "express" 

this might be auto imported by vs code or by react so just delete this.



来源:https://stackoverflow.com/questions/59903475/typeerror-cannot-read-property-prototype-of-undefined-react-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!