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

vitest fails when using node v18.17.0 - TypeError: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of URL #3826

Closed
6 tasks done
sandrosc opened this issue Jul 27, 2023 · 3 comments · Fixed by #3828
Labels
Milestone

Comments

@sandrosc
Copy link

Describe the bug

 FAIL  test/App.test.tsx [ test/App.test.tsx ]
TypeError: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of URL
 ❯ Object.openSync node:fs:595:10
 ❯ readFileSync node:fs:471:35
 ❯ node_modules/vitest/node_modules/vite/dist/node/constants.js:5:32

Serialized Error: {
  "code": "ERR_INVALID_ARG_TYPE",
}

 Test Files  1 failed (1)
      Tests  no tests
   Start at  16:23:56
   Duration  1.23s (transform 28ms, setup 0ms, collect 0ms, tests 0ms, environment 620ms, prepare 119ms)

Apparently node v18.17.0 comes with a new URL parser, which might explain why the check if the path argument is an URL fails. This might also be a node issue. We fixed it by upgrading to node v20, but downgrading should also work.

Reproduction

Run vitest with a test on node v18.17.0.

System Info

This issue first occurred in a github action workflow:
- ubuntu-latest github image
- actions/setup-node@v3 with node-version 18

Used Package Manager

yarn

Validations

@AriPerkkio
Copy link
Member

AriPerkkio commented Jul 27, 2023

This can be reproduced on Vitest's test cases: test/web-worker. Tests fail constantly:

 DEV  v0.33.0 /x/vitest/test/web-worker

 ❯ test/clone.test.ts (0)
 ❯ test/sharedWorker.spec.ts (0)
 ❯ test/postMessage.test.ts (0)
 ❯ test/init.test.ts (0)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 4 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/clone.test.ts [ test/clone.test.ts ]
 FAIL  test/init.test.ts [ test/init.test.ts ]
 FAIL  test/postMessage.test.ts [ test/postMessage.test.ts ]
 FAIL  test/sharedWorker.spec.ts [ test/sharedWorker.spec.ts ]
TypeError: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of URL
 ❯ Object.openSync node:fs:595:10
 ❯ readFileSync node:fs:471:35
 ❯ ../../node_modules/.pnpm/vite@4.3.9_@types+node@18.7.13/node_modules/vite/dist/node/constants.js:5:32

This error is coming up randomly on CI too.

Is this a NodeJS bug? The error message makes no sense:

TypeError: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of URL

@AriPerkkio
Copy link
Member

This only fails on jsdom. The URL instance passed to readFileSync makes Node throw an error now. Vitest test environments node and happy-dom work fine.

@sheremet-va
Copy link
Member

It probably doesn't work because URL in jsdom is replaced with a custom implementation.

@sheremet-va sheremet-va added this to the 0.34.0 milestone Jul 28, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants