Comments (10)
Similar issue here. Running tests using vitest
in a "node" environment works but running with "jsdom" stops with the following:
Error: The "path" argument must be of type string or an instance of URL. Received an instance of URL
❯ makeError ../../.pnp.cjs:36106:34
❯ applyNodeExportsResolution ../../.pnp.cjs:37438:13
❯ resolveUnqualifiedExport ../../.pnp.cjs:37824:35
❯ resolveRequest ../../.pnp.cjs:37909:106
❯ Object.resolveRequest ../../.pnp.cjs:37966:26
❯ resolve$1 ../../.pnp.loader.mjs:1997:21
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'ERR_INVALID_ARG_TYPE', pnpCode: 'EXPORTS_RESOLUTION_FAILED', data: { unqualifiedPath: '/Users/rob/Projects/Elixir/core-develop/.yarn/cache/@vitest-runner-npm-0.34.6-dae9162b5c-3525d8e4f8.zip/node_modules/@vitest/runner/utils', locator: { name: '@vitest/runner', reference: 'npm:0.34.6' }, pkgJson: { name: '@vitest/runner', type: 'module', version: '0.34.6', description: 'Vitest test runner', license: 'MIT', funding: 'https://opencollective.com/vitest', homepage: 'https://github.com/vitest-dev/vitest/tree/main/packages/runner#readme', repository: { type: 'git', url: 'git+https://github.com/vitest-dev/vitest.git', directory: 'packages/runner' }, bugs: { url: 'https://github.com/vitest-dev/vitest/issues' }, sideEffects: true, exports: { '.': { types: './dist/index.d.ts', import: './dist/index.js' }, './utils': { types: './dist/utils.d.ts', import: './dist/utils.js' }, './types': { types: './dist/types.d.ts', import: './dist/types.js' }, './*': './*' }, main: './dist/index.js', module: './dist/index.js', types: './dist/index.d.ts', files: [ 'dist', '*.d.ts' ], dependencies: { 'p-limit': '^4.0.0', pathe: '^1.1.1', '@vitest/utils': '0.34.6' }, scripts: { build: 'rimraf dist && rollup -c', dev: 'rollup -c --watch' } }, subpath: 'utils', conditions: { constructor: 'Function<Set>', has: 'Function<has>', add: 'Function<add>', delete: 'Function<delete>', clear: 'Function<clear>', entries: 'Function<entries>', forEach: 'Function<forEach>', size: 3, values: 'Function<values>', keys: 'Function<values>' }, request: '@vitest/runner/utils', issuer: '/Users/rob/Projects/Elixir/core-develop/.yarn/__virtual__/vitest-virtual-68e5eaf46b/0/cache/vitest-npm-0.34.6-48e1d6f80a-0191422ab9.zip/node_modules/vitest/dist/index.js' } }
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
I think this is due to the dynamic import inside vitest
here
from vitest.
Shoot! It looks like one indeed. I hope however that the research, workarounds, and reproducible repo will come in handy.
from vitest.
Contrary to what this ticket is about I have switched to happy-dom
by defining the dependency in .yarnrc.yml
and changing the test file comment header. My tests now work.
packageExtensions:
local-pkg@*:
peerDependencies:
"happy-dom": "*"
from vitest.
I am getting the same error as #4413 (comment)
FAIL tests/unit/services/browserCheck.test.js [ tests/unit/services/browserCheck.test.js ]
Error: The "path" argument must be of type string or an instance of URL. Received an instance of URL
❯ makeError .pnp.cjs:25457:34
❯ applyNodeExportsResolution .pnp.cjs:26789:13
❯ resolveUnqualifiedExport .pnp.cjs:27175:35
❯ resolveRequest .pnp.cjs:27260:106
❯ Object.resolveRequest .pnp.cjs:27317:26
❯ resolve$1 .pnp.loader.mjs:2019:21
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'ERR_INVALID_ARG_TYPE', pnpCode: 'EXPORTS_RESOLUTION_FAILED', data: { unqualifiedPath:
....
However this appears to only affect 0.34.6
. If I downgrade to vitest 0.34.5
then the tests work fine.
Using Yarn 4.0.2 with PNP. Vite 4.5.0
from vitest.
Looks like this is a duplicate of #899
from vitest.
This is because node‘s URL is overriden by jsdom URL
from vitest.
This is because node‘s URL is overriden by jsdom URL
Ok, so is there a fix or workaround?
from vitest.
You can override URL in setup files:
import { URL } from 'node:url'
globalThis.URL = URL
This might break some JSDOM API.
from vitest.
@sheremet-va Unfortunately this doesn't work. vitest crashes with the error before the setup files are executed. Additionally, it can't be added to the global setup or the vitest config.
I don't quite understand why this hack is required since it works perfectly well if using the normal node_modules
mode.
from vitest.
I guess it uses global URL which is overriden by jsdom and incompatible with "path" module (url parser was updated in Node bot so long ago)
from vitest.
Related Issues (20)
- Fixtures are not passed to the test function when using `test.each()` HOT 14
- Vitest always writes snapshot files on Windows 10 with Node 18.17.1
- `SyntaxError: The requested module 'execa' does not provide an export named 'default'` when installing dependency HOT 2
- Unnecessary (?) check for if vite is installed
- Coverage ignores vite.config.js file in versions >= 1.0.0-beta.0 HOT 10
- Snapshot with more than a handful of lines
- Odd behavior with `toThrowErrorMatchingInlineSnapshot` with multiline error message
- Unable to access input field in vitest dom HOT 1
- Istanbul Coverage: "Error: Invalid file coverage object, missing keys" HOT 2
- vitest freezes when extending a test and testTimeout occurs HOT 6
- `--changed` not propagating to yarn workspaces HOT 1
- Vitest 1.0.1 breaks mocked constructors due to unmocked getters HOT 1
- Yarn PnP (`nodeLinker: pnp`) throws an error of `MISSING DEP Can not find dependency 'vite' ` HOT 8
- Fixture teardown error is not treated as test failure HOT 1
- Bug: test throws an error when using a MouseEvent with jsdom environment HOT 7
- unhandled error with browser tests and modified `base` HOT 6
- Suddenly can't run tests: "Error: Cannot merge config in form of callback" HOT 1
- @types/chai conflict with @vitest/expect/dist/chai.d.cts HOT 10
- Position of test filter vs. flags for running single tests HOT 2
- `--coverage.all=false` doesn't work for vitest workspace HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vitest.