msw: ReferenceError: location is not defined in Node.js
Prerequisites
- I confirm my issue is not in the opened issues
- I confirm the Frequently Asked Questions didn’t contain the answer to my issue
Environment check
- I’m using the latest
mswversion - I’m using Node.js version 14 or higher
Node.js version
18.14.2
Reproduction repository
https://github.com/till/msw-location-error
Reproduction steps
npm install
./node_modules/.bin/vitest
Current behavior
FAIL tests/request.test.js > request
ReferenceError: location is not defined
❯ FetchInterceptor.<anonymous> node_modules/@mswjs/interceptors/src/interceptors/fetch/index.ts:50:22
❯ step node_modules/@mswjs/interceptors/lib/interceptors/fetch/index.js:59:23
❯ Object.next node_modules/@mswjs/interceptors/lib/interceptors/fetch/index.js:40:53
❯ fulfilled node_modules/@mswjs/interceptors/lib/interceptors/fetch/index.js:31:58
Expected behavior
I can mock the request
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 4
- Comments: 16 (7 by maintainers)
I am also running into this, and finding it hard to create a consistent reproduction case; as it works locally, but fails in GitHub actions, CI/CD land.
I can confirm I am on
0.17.9:error observed:
unfortunately upgrading to the latest
@mswjs/interceptorsdoes not work. Happy to create a new issue if one does not already exist, as I think this case is slightly different than the original #1555 one.I ran into this issue and could not solve it on pnpm only by running the install again. It did not update the pnpm-lock so I had to override the
msw>@mswjs/interceptorsto the latest version, installed and then removed the override and it installed again, the correct version this time. Don’t ask me why ¯_(ツ)_/¯@joshkel, this has been fixed by @till and is published already. Re-install your dependencies and you will get the fix automatically. To verify:
Should print
0.17.8.@till, that would be awesome! Are you comfortable with branching changes from a specific moment of Git history? As I’ve mentioned, the line we have to fix is not in the latest state of the Interceptors repo. It’s nothing too complex though:
@mswjs/interceptorsrepo.git checkout chore/0.17.7git checkout -b fix/fetch-locationfix/fetch-locationtochore/0.17.7I think you need my help with
chore/0.17.7to open a PR to that branch on the original repo and not on your fork.Edit: I’ve pushed
chore/0.17.7to the origin so you should be able to go from there and open a pull request to that intermediate branch.I can try to upgrade it? 🥳