Getting "ReferenceError: Response is not defined" while trying to upgrade an app from next 11 to next 12
See original GitHub issueWhat version of Next.js are you using?
12.0.0
What version of Node.js are you using?
16.3.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
next build + next start
Describe the Bug
I am trying to upgrade Next.js version in a big application from v11.0.1 to Next.js 12. It uses Next with express.js. I’m getting the following error:
ReferenceError: Response is not defined
at Object.<anonymous> (/Users/andreisena/projects/.../node_modules/next/dist/server/web/spec-extension/response.js:23:28)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.wrappedLoad [as _load] (/Users/andreisena/projects/.../node_modules/newrelic/lib/shimmer.js:373:24)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (/Users/andreisena/projects/.../node_modules/next/dist/server/next-server.js:47:17)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
Expected Behavior
To work correctly like v11
To Reproduce
I couldn’t reproduce it yet on a fresh install of Next.js and I cannot share the repo since it is private. But if I find something new I will post here.
What I could see in a fresh install is that when I debug Response in server/web/spec-extension/response.js
, it has the same contract as node-fetch Response. Is that correct?
Object [Response] {
url: [Getter],
status: [Getter],
ok: [Getter],
redirected: [Getter],
statusText: [Getter],
headers: [Getter],
clone: [Function: clone],
body: [Getter],
bodyUsed: [Getter],
arrayBuffer: [Function: arrayBuffer],
blob: [Function: blob],
json: [Function: json],
text: [Function: text],
buffer: [Function: buffer],
textConverted: [Function: textConverted]
}
By the way, on the main application, Response always come as undefined.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Response is not defined (trying to upgrade from NextJS 11 to ...
Hi all,. I'm trying to upgrade our project from Next 11 to 12. However, i'm unable to get our custom server to start...
Read more >Why am I getting ReferenceError: Response is not defined?
I am trying to set up a basic server, but have no idea why I am getting a response error. var http =...
Read more >Upgrade Guide - Next.js
Upgrade Guide. Upgrading from 12 to 13. To update to Next.js version 13, run the following command using your preferred package manager:
Read more >ReferenceError: response is not defined (Example) - Treehouse
ReferenceError : response is not defined. When go to the server I am getting the following error: Server running at http://<workspace-url>/ ...
Read more >How to Fix Uncaught ReferenceError: $ is not defined in jQuery
If you're still getting this error there might be some other reasons, for example, if you have a local copy of the jQuery...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
By default Next will polyfill some fetch APIs (Request, Response, Header and fetch) only if
fetch
is not found in the global scope in certain entry points. If we have a custom server which is adding a global fetch (and only fetch) at the very top then the rest of APIs will not be polyfilled. We can reproduce it with the minimal Express example:With the introduction of Middleware, all web code must run in a Sandbox outside of the Node main process where we inject all polyfills. Right now we are using one dependency in the server that should not be there. I’m working on a small refactor to fix this case.
NodeJS Version: 14.17.6
I have a similar Issue. I call “axios.request(<axiosRequestArgs>)” on the client side which should return an AxiosPromise. This works fine on next@11.1.2. When I upgrade next to 12.0.0 / 12.0.1 I get the following error when I try to resolve the promise: “TypeError: Cannot read properties of undefined (reading ‘then’)” The request isn’t made at all, since it don’t appear in the network tab of the Chrome Devtools.