'Error: No known conditions for "./node" specifier in "msw" package' when using MSW with Vitest

Open
#125 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Active
Tech stack
typescript, vite

Research direction

Start with the import of msw/node in src/testfile.test.ts and reproduce it under Vitest with the plugin enabled. Compare the result after removing the plugin, then trace the reported Vite resolution error to determine whether the plugin or MSW causes it. Done means the import works with the plugin present and the error no longer occurs.

Written by the indexing model from the issue text.

Description

Trying to import and use any function from MSW (specifically, msw/node) when running vitest prints this error:

 FAIL  src/testfile.test.ts [ src/testfile.test.ts ]
Error: No known conditions for "./node" specifier in "msw" package
 ❯ e node_modules/.pnpm/vite@4.5.0_@types+node@20.8.10/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:21445:25
 ❯ n node_modules/.pnpm/vite@4.5.0_@types+node@20.8.10/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:21445:646
 ❯ o node_modules/.pnpm/vite@4.5.0_@types+node@20.8.10/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:21445:1297
 ❯ resolveExportsOrImports node_modules/.pnpm/vite@4.5.0_@types+node@20.8.10/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:28746:20
 ❯ resolveDeepImport node_modules/.pnpm/vite@4.5.0_@types+node@20.8.10/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:28765:31
 ❯ tryNodeResolve node_modules/.pnpm/vite@4.5.0_@types+node@20.8.10/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:28453:20
 ❯ Context.resolveId node_modules/.pnpm/vite@4.5.0_@types+node@20.8.10/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:28212:28
 ❯ Object.resolveId node_modules/.pnpm/vite@4.5.0_@types+node@20.8.10/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:44276:32
 ❯ TransformContext.resolve node_modules/.pnpm/vite@4.5.0_@types+node@20.8.10/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:43992:23

This only happens when this plugin is present, removing it seems to fix the issue.

Not sure if this is a bug in the plugin, or a problem on msw's side, or if I'm maybe doing something wrong?

Dominant language
TypeScript
Stars
520
Forks
70
Avg merge
23h 35m
Merged PRs (30d)
39

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from solidjs/solid-vite-plugin

All issues in solidjs/solid-vite-plugin

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.