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

Clearer error message when node: null condition prevents subpath import #3377

Closed
IanVS opened this issue Sep 12, 2023 · 1 comment
Closed

Comments

@IanVS
Copy link

IanVS commented Sep 12, 2023

I hit a snag when trying to bundle msw@next using tsup (which sets platform: node, apparently). It took me a while to figure out what was happening, because the error message was confusing:

✘ [ERROR] Could not resolve "msw/browser"

    lib/msw-config.ts:2:46:
      2 │ import { setupWorker, type SetupWorker } from 'msw/browser';
        ╵                                               ~~~~~~~~~~~~~

  The path "./browser" is not exported by package "msw":

    node_modules/msw/package.json:9:13:
      9 │   "exports": {
        ╵              ^

  The file "./lib/browser/index.js" is exported at path "./browser":

    node_modules/msw/package.json:21:17:
      21 │       "default": "./lib/browser/index.js"
         ╵                  ~~~~~~~~~~~~~~~~~~~~~~~~

  Import from "msw/browser" to get the file "node_modules/msw/lib/browser/index.js":

    lib/msw-config.ts:2:46:
      2 │ import { setupWorker, type SetupWorker } from 'msw/browser';
        │                                               ~~~~~~~~~~~~~
        ╵                                               "msw/browser"

  You can mark the path "msw/browser" as external to exclude it from the bundle, which will remove
  this error.

1 error

I realized eventually that this was happening because msw sets a condition of "node": null to prevent the import in node environments.

So I understand why this is happening now, but it took a while to figure it out. I think some more information in the error message would be really useful. Maybe just something simple like, The path "./browser" is not exported by package "msw", due to the "node": null condition.

@evanw
Copy link
Owner

evanw commented Sep 12, 2023

Thanks for the report and the test case. I haven't seen packages use null in the wild before like this.

@evanw evanw closed this as completed in 5ecf535 Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants