8000 Error: No "exports" main defined in /.../package.json · Issue #41 · colinhacks/zshy · GitHub
[go: up one dir, main page]

Skip to content

Error: No "exports" main defined in /.../package.json #41

Open

Description

@ericclemmons

This may be a playwright issue, but I discovered that running npx playwright test would get this error if it did not have a default exports:

Error: No "exports" main defined in /.../package.json

Adding 1 line fixed it, so I'm wondering if this should be the default (heh :D):

  "exports": {
    ".": {
+     "default": "./dist/index.js",
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js"
    }
  },
  "scripts": {
    "build": "zshy",
    "lint": "tsc --noEmit"
  }
}

I know I can auto-generation of exports and do it myself, but I'm wondering if this should be default behavior.

https://github.com/colinhacks/zshy?tab=readme-ov-file#can-i-prevent-zshy-from-modifying-my-packagejson

Activity

  1. colinhacks commented on Sep 19, 2025

    @colinhacks
    Owner

    Ah interesting. When you set cjs: false zshy won't set any "require" condition. So in a CJS context (e.g. if your package/app doesn't contain "type":"module") the package won't be loadable. You could argue this is desirable since you've explicitly disabled CJS here. Assuming that you've forgotten "type":"module" in your package.json, this is possibly revealing a useful "bug" in your codebase. I'll think about this a little more. Setting "default" is probably a good idea.

    FYI condition order matters in package.json/#exports so you should always put "default" last to avoid weird issues. 👍

  2. colinhacks commented on Oct 5, 2025

    @colinhacks
    Owner

    The root of the playwright issue is that it's trying to resolve to a CommonJS version of your package. It's a little weird that default works here, and it's a quirk of Playwright's module resolution I guess. I'm hesistant to blindly throw in "default" conditions. In a true CommonJS environment it would cause issues if a require resolved to an ESM file. It's weird that it doesn't cause issues in Playwright here. But if you want to avoid stuff like this you probably just shouldn't disable CJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0