-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
Unable to use msw/node for testing solid-js due to resolve.conditions
set to browser
#2092
Comments
Hi, @nknapp. Thanks for reporting this. You must configure your tooling to use the MSW uses the conditional exports correctly: you must not import |
Thanks, I have opened an issue with the plugin and will try your workaround. As I said there. I think it is debatable. Since the user has to explicitly import |
@kettanaito I have tried your suggestion and modified This still does not work, because the resolve.exports code iterates the keys of the export definition and returns the first matching key, which is I haven't tried though, if testing solidjs components would work as well.... |
@kettanaito I got some more insight and a better solution. The resolution algorithm will iterate the keys of the exports object and take the first match. The order or keys is significant (see this answer in the For If you intend resolution to fail for browser builds and succeeds for Node.js, it should look like this:
First look for 'node" and succeed. Then look for "browser" and fail. I have updated my reproduction example https://github.com/nknapp/msw-solid-testing-library-bug-reproduction to
Would be nice if you could reopen this issue. |
Thanks for all the work you did narrowing down this issue, @nknapp. As it happens, I just finished a migration from
But, I am seeing a similar error when running
It looks like the key order in the main "./ClientRequest": {
+ "node": {
+ "require": "./lib/node/interceptors/ClientRequest/index.js",
+ "import": "./lib/node/interceptors/ClientRequest/index.mjs"
+ },
"browser": null,
"types": "./lib/node/interceptors/ClientRequest/index.d.ts",
"require": "./lib/node/interceptors/ClientRequest/index.js",
"import": "./lib/node/interceptors/ClientRequest/index.mjs",
"default": "./lib/node/interceptors/ClientRequest/index.js"
}, The main difference in my setup is the Vite ecosystem library versions are a bit older: {
"vitest": "0.34.1",
"vite": "4.4.10"
"vite-plugin-solid": "2.7.0",
"solid-js": "1.7.12",
"msw": "2.2.14"
} |
I am facing the same problem with vitest. |
@MarkLeMerise I haven't looked at the issue anymore, since I was occupied with other things. But if you think your patch is correct and if it matches the change in the main module, would you mind opening a PR? You will get my upvote. I think, since this issue is closed already, the information might get lost here. |
Prerequisites
Environment check
msw
versionNode.js version
Tested in v18.15.0 and v20.11.1
Reproduction repository
https://github.com/nknapp/msw-solid-testing-library-bug-reproduction
Reproduction steps
Run
Current behavior
The test output for the loadValue.test.ts is
The error occurs, because the
vite-plugin-solid
sets the vite configuration option resolve.conditions to['browser']
and because the package.json of bothmsw
and@mswjs/interceptors
specifybrowser: null
for imports being used.This is the extract of the
msw
package.jsonOn the other hand, if the plugin would not specify this condition,
vite
would load thessr
version of solid-js, providing and emptyrender
function.Expected behavior
The
loadValue
test should pass.In fact, I can make it pass, by copying the
default
key to thebrowser
key in the package.json exports.In
msw
In
@mswjs/interceptors
:The text was updated successfully, but these errors were encountered: