Search code examples
javascriptreactjsexpressmern

React App suddenly stopped working; TypeError: Cannot read properties of undefined (reading 'prototype')


I didn't make any major changes to my app and it was running fine until I started getting this error

TypeError: Cannot read properties of undefined (reading 'prototype')

(anonymous function)
.../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.

I've tried reverting any changes I made to my code and I deleted node_modules and ran npm install again but the error remains


Solution

  • There's a bit too little context here to take a confident guess as to what the issue may be.

    Can you verify where this error takes place? Is it a browser error, or an error in a node process? It seems like the error takes place in the client's node_modules. Is you client an express server?

    The only thing I can decipher is that the http module is probably missing where you are requiring code that required response from express.

    One issue people seem to be having when it comes to these kinds of errors is that their IDE has accidentally auto imported response from express

    import { response } from 'express'
    

    when they've written response handlers in the UI

    .then((response) => ...)
    

    You could try to search through your application and make sure that you are not making such an import in files that will end up for instance in the browser.