-
-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot assign to read only property 'Headers' of object '[object Object]' #2281
TypeError: Cannot assign to read only property 'Headers' of object '[object Object]' #2281
Comments
Here's the function in question: https://github.com/mswjs/interceptors/blob/4227c6eb360f490f1448860c8cfb2ac2a9688225/src/interceptors/ClientRequest/utils/recordRawHeaders.ts. We are defining properties in two places there: Object.defineProperty(headers, kRawHeaders, { Object.defineProperty(Headers, kRestorePatches, { Perhaps one of them throws. What's interesting is that both Node.js v18 and v20 test suites are passing. This needs to be investigated by reproducing the issue and looking at the exact stack trace pointing to the built modules. |
@ch-liuzhide hi 👋 Can you please share more info on this issue? What version of Node.js are you using? Is there a chance to publish a reproduction repo for this? That'd help a lot. Thanks. |
I can give more context @kettanaito. I run on Node
So I assume here? |
Thanks. I'd think so but that assigns on the |
I'm getting this stack trace which sounds similar, although I'm not sure if it's the same issue. For me it occurs whenever I attempt to make a fetch request from the server during SSR. I'm on Node
I don't have a neat sourcemap like the one above, but in my node_modules folder, Request = new Proxy(Request, {
construct(target, args, newTarget) {
if (typeof args[1] === "object" && args[1].headers != null && args[1].headers instanceof Headers && Reflect.has(args[1].headers, kRawHeaders)) {
args[1].headers = args[1].headers[kRawHeaders]; // <----------- this is line 205
}
const request = Reflect.construct(target, args, newTarget);
if (typeof args[1] === "object" && args[1].headers != null) {
defineRawHeaders(request.headers, inferRawHeaders(args[1].headers));
}
return request;
}
}); I think that maps to here: |
Root causeThis was causing the problem, the restoration line: https://github.com/mswjs/interceptors/blob/017469ed8cf59858ee02ec7826f4924ee7639fee/src/interceptors/ClientRequest/utils/recordRawHeaders.ts#L58. And that was caused by interceptors just reassigning global Fix is open at mswjs/interceptors#638 |
Released: v2.4.7 🎉This has been released in v2.4.7! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Unfortunately bug is still exist. Now it seems in here
|
@ctklc, what environment are you running in? I'd need a reproduction repository to reopen this. If you can provide one, I'd be grateful. |
Ah yeah we are using JSDOM and again because of |
I'm afraid nothing I can do in that case. Here's the library's stance on supporting Jest/JSDOM. I've wasted way too many hours trying to patch holes on that sinking ship. It's in shared interest to put our energy elsewhere. You can start from migrating to |
Discussed in #2271
Originally posted by ch-liuzhide September 10, 2024
I encountered the following error after updating the node_modules folder and then running the tests,
Does anyone have similar mistakes? How should I deal with it?
The text was updated successfully, but these errors were encountered: