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 set property headers of #<_Request> which has only a getter #2290

Closed
4 tasks done
stevensacks opened this issue Sep 17, 2024 · 9 comments · Fixed by #2293
Closed
4 tasks done

TypeError: Cannot set property headers of #<_Request> which has only a getter #2290

stevensacks opened this issue Sep 17, 2024 · 9 comments · Fixed by #2293
Assignees
Labels
bug Something isn't working scope:node Related to MSW running in Node

Comments

@stevensacks
Copy link

Prerequisites

Environment check

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

Node.js version

20.17.0

Reproduction repository

https://github.com/gaia-react/remix

Reproduction steps

  1. Run npx create-remix@latest --template gaia-react/remix
  2. npm install msw@2.4.8 (it's currently using 2.4.2 which is the last working version)
  3. npm run dev to launch Remix server
  4. Click on "Auth Example"
  5. Type in the password passw0rd (zero for o) and click the Login button
  6. TypeError occurs - MSW handler does not get called

Current behavior

I'm using remix-auth to make the call to the login endpoint, but it doesn't make it to the defined MSW handler.

If you need the console log of the error to show up in the terminal process, add it here after line 21.

TypeError: Cannot set property headers of #<_Request> which has only a getter
      at Object.construct (file:///Users/stevensacks/Development/gaia/framework/remix/node_modules/@mswjs/interceptors/lib/node/chunk-RWGRRMVU.mjs:217:27)
      at Authenticator.authenticate (/Users/stevensacks/Development/gaia/framework/remix/node_modules/remix-auth/build/authenticator.js:68:41)

Expected behavior

Expect the API call to go through to the MSW handler, as it does in version 2.4.2.

@stevensacks stevensacks 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 17, 2024
@hugotiburtino
Copy link

hugotiburtino commented Sep 18, 2024

Same here. See error in CI

To reproduce, just clone the repo, check the branch dependabot/npm_and_yarn/msw-2.4.7 out, install with yarn and run yarn test

@kettanaito
Copy link
Member

@stevensacks, can you please point me to what exact request handler you expect to be called?

@kettanaito
Copy link
Member

I believe I tracked down the issue. Opened a fix at mswjs/interceptors#640. Will propagate to MSW soon.

I'd love to know more details on the expected result. The error is not thrown anymore in your code, but nothing happens on the page. I can see the 302 response arriving as error in your auth logic. That seems to be related to your application (maybe that's intentional?).

@kettanaito kettanaito self-assigned this Sep 19, 2024
@kettanaito kettanaito removed the needs:triage Issues that have not been investigated yet. label Sep 19, 2024
@stevensacks
Copy link
Author

That is odd. Login was working before with the msw handler (inside the test folder) as written. I’ll look into it asap.

@stevensacks
Copy link
Author

Seems to be a bug in remix-auth. It's not storing the session correctly.

Login succeeds
Redirects to /profile
Profile loader authenticator.isAuthenticated fails
Redirects to /login

From the user side, it appears to never leave the login page.

@kettanaito
Copy link
Member

We did release some fixes around redirects in MSW, but those are suppose to follow redirects correctly (that was never done before). They are also relevant to fetch only. In your case, you are using ClientRequest in Node.js, so you can disregard this message.

I believe the underlying issue is fixed. We didn't cover one Request constructor scenario when recording raw headers. I will propagate the fix to MSW, and you will have no errors in your auth logic.

@stevensacks
Copy link
Author

stevensacks commented Sep 20, 2024

The reason it wasn't redirecting to /profile after login was a mistake in my code. remix-auth's authenticator throws a redirect on success, but my try catch around it was handling it as if it was an error instead of rethrowing it. It's working now in 2.4.8.

@kettanaito
Copy link
Member

Awesome! 🎉 Good job on figuring that out. Meanwhile, the fix is about ready. Will publish today.

@kettanaito
Copy link
Member

Released: v2.4.9 🎉

This has been released in v2.4.9!

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 scope:node Related to MSW running in Node
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants