Skip to content
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 'Request' of object '[object Window]' #2276

Closed
4 tasks done
hays0503 opened this issue Sep 11, 2024 · 11 comments · Fixed by mswjs/interceptors#638 or #2283
Closed
4 tasks done
Assignees
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@hays0503
Copy link

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Node.js version

v20.16.0

Reproduction repository

https://github.com/hays0503/sck1

Reproduction steps

Run test "test:coverage": "jest --coverage"
And get error
Screenshot_1

FAIL src/entities/ComponentSelectCity/ui/test/ComponentSelectCity.test.tsx
× Фильтрация городов при поиске

● Фильтрация городов при поиске

TypeError: Cannot assign to read only property 'Request' of object '[object Window]'

Current behavior

I noticed that the error started appearing with version 2.4.4. I rolled back to older versions and the problem was solved.

Expected behavior

Fixing the problem

@hays0503 hays0503 added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Sep 11, 2024
@ddolcimascolo
Copy link

@kettanaito

It looks like 2.4.4 really has something weird, it's like the third issue breaking people tests. Maybe you'd want to deprecate it on npm until a new version can be released?

David

@JSingmin
Copy link

I've gotten this error too after running an npm audit fix, first using msw 2.1.3 and also trying 2.4.5

@ghost91-
Copy link

We have a similar issue:

[2024-09-11T12:59:24.766Z]     TypeError: Cannot assign to read only property 'Headers' of object '[object Object]'
[2024-09-11T12:59:24.766Z] 
[2024-09-11T12:59:24.766Z]       4 |
[2024-09-11T12:59:24.766Z]       5 | export function prepareMockServer(mockServer: SetupServer): void {
[2024-09-11T12:59:24.766Z]     > 6 |     mockServer.listen();
[2024-09-11T12:59:24.766Z]         |                ^

@hays0503
Copy link
Author

Temporarily solved the problem by rolling back to an older version of the library ("msw": "^2.4.3")

@hays0503 hays0503 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2024
@hays0503 hays0503 reopened this Sep 11, 2024
@rachel-bernard
Copy link

I have the exact same issue after upgrading to the lastest version of msw.
Fixed by rolling back to v2.4.3, as other commenters have said.

@AdrienFromToulouse
Copy link

confirmed, since 2.4.4 our tests fail in the same manner.
TypeError: Cannot assign to read only property 'Request' of object '[object Window]' on a beforeAll(() => server.listen());

@hays0503 hays0503 reopened this Sep 12, 2024
@Igosuki
Copy link

Igosuki commented Sep 13, 2024

I narrowed it down to this commit :

mswjs/interceptors@4660558#diff-9be9bd59c25c2573eca1764259102bcd08087e15b997c3cede7e51ceaaa5df9fR106

Overriding the dependency fixes the bug : "@mswjs/interceptors": "0.32.1"

@kettanaito
Copy link
Member

This has a similar root cause and the fix as #2281 (comment).

@kettanaito
Copy link
Member

@davesidious,

Maybe you'd want to deprecate it on npm until a new version can be released?

There is no concept of deprecating or unpublishing a package on NPM. Software has bugs, and we've done a ton of changes and improvements in that Interceptors update. Honestly, it's a surprisingly little number of bugs, and most of them are related.

You should pin MSW to a specific version that worked for you until the issues are resolved. That's how to handle it in open source.

@ghost91-
Copy link

There is no concept of deprecating or unpublishing a package on NPM.

That’s actually incorrect, see https://docs.npmjs.com/deprecating-and-undeprecating-packages-or-package-versions

That said, I agree that it’s not really necessary in this particular case, especially since there seems to be a fix now.

@kettanaito
Copy link
Member

Released: v2.4.7 🎉

This has been released in v2.4.7!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
8 participants