question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Path errors on windows

See original GitHub issue

Describe the bug

Getting the following error messages when running in a test environment when doing server.use(rest.get(…)) after setting up. Works first but throws error when trying to change a route to return something else after initialization.

    Invalid URI "c:/Users/..projectdir../services/web/src/util/toastr.js"

      at Request.init (node_modules/request/request.js:273:31)
      at new Request (node_modules/request/request.js:127:8)
      at request (node_modules/request/index.js:53:10)
      at Object.createClient (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:358:29)
      at XMLHttpRequestImpl.send (node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:642:31)
      at XMLHttpRequest.send (node_modules/jsdom/lib/jsdom/living/generated/XMLHttpRequest.js:309:34)
      at node_modules/node-request-interceptor/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts:387:29

and the same error for /node_modules/stacktrace-js/stacktrace.js, node_modules/jquery/dist/jquery.js, /node_modules/node-request-interceptor/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts etc.

Environment

  • OS: windows 10
  • msw: 0.26.2
  • nodejs: 12.13.0
  • npm: 6.14.11

Please also provide your browser version. Using on CL

To Reproduce

Steps to reproduce the behavior:

  1. setup server
  2. after setting up and listen() , do server.use(rest.get(…))

Expected behavior

it should work, works on coworkers machine with everything the same (node version, npm, lib version (same repo)). Only difference is he is using OSX and me windows 10. Works in the pipeline as well running linux.

Screenshots

If applicable, add screenshots to help explain your problem.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kettanaitocommented, Mar 4, 2021

I’ve tried this on Windows 10 and din’t experience the issue. Here’s the test file:

import { rest } from 'msw';
import { setupServer } from 'msw/node'

const server = setupServer(
  rest.get('/user', (req, res, ctx) => res(ctx.json({ id: 1 })))
)

beforeAll(() => server.listen())
afterAll(() => server.close())

test('applies runtime handler on Windows 10', async () => {
  server.use(
    rest.get('/user', (req, res, ctx) => res(ctx.json({ id: 2 })))
  )

  const res = await fetch('/user')
  expect(await res.json()).toEqual({ id: 2})
});

The test passes successfully. It must have been something in your configuration that made relative request URLs in tests resolve against your process.cwd().

1reaction
kettanaitocommented, Mar 2, 2021

I can give it a try on a Windows machine and update this issue. From the error message, it seems that there was an attempt to create a URL instance from a relative path that was resolved against your process.cwd or similar. MSW doesn’t handle relative URL paths in Node.js, JSDOM (or another DOM-like environment) does. Since Jest polyfills window.location, relative URLs get resolved against the stub, which I believe is http://localhost. In pure Node.js relative URLs cannot exist (nothing to be relative to).

Most likely the issue was indeed somewhere in your setup. @sebwalle thank you for looking into it. Could you please update us on what caused this issue? It’d be useful for posterity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Windows cannot access the specified device, path, or file ...
Method 1: Check the permission of the file or folder · Method 2: Check the file location · Method 3: Make sure that...
Read more >
Full Fix: ERROR_PATH_NOT_FOUND error on Windows 10, 7
Another cause for System cannot find path specified error can be file corruption. Sometimes your Windows installation can get corrupted, and ...
Read more >
Fix Windows Cannot Access the Specified Device Path/File ...
The error “Windows cannot access the specified device path or file” is common when users try to install, update or start Windows 10....
Read more >
How to fix “The system cannot find the specified path” error
The Windows error “The system cannot find the specified path” usually occurs if you use an invalid path when downloading or saving, if...
Read more >
11 Ways To Fix “The System Cannot Find The Path Specified ...
How to Fix the “System Cannot Find the Path Specified” Error · Check if the Path is Correct · Check Environment Variables ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found