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

No exports defined error with Next.js TS config #7

Closed
victorteokw opened this issue Dec 10, 2024 · 3 comments
Closed

No exports defined error with Next.js TS config #7

victorteokw opened this issue Dec 10, 2024 · 3 comments

Comments

@victorteokw
Copy link

When use this with Next.js TypeScript config, this module cannot be found.

By add one line in package.json fixes this problem.

  "exports": {
    ".": {
      "types": "./types/index.d.ts",
      "import": "./dist/index.mjs",
      "default": "./dist/index.mjs",
    }
  },
@slevithan
Copy link
Owner

slevithan commented Dec 24, 2024

See discussion on PR #8. Something in some people's pipeline is trying to load this module as CJS even though it's ESM only. Based on other people's experiences, using next.config.mjs instead of next.config.ts might fix the issue, as might upgrading Vite (to 5.x) or other build tools.

The fix suggested by @victorteokw above (adding default to exports) doesn't seem like the right one, since it will likely lead to some build tools trying to use the ESM module as CJS.

Whatever the underlying issue is likely needs to be reported and fixed in other tools, but I'm open to other suggestions for how package.json could be updated to work around the problem.

@wisdomstar94
Copy link

wisdomstar94 commented Dec 25, 2024

Next.js has recently started supporting next.config.ts.
image


The same thing happens to me when I use next.config.ts.
image


However, it works well with next.config.mjs without errors.

@slevithan slevithan changed the title Missing default export No exports defined error with Next.js TS config Dec 28, 2024
@slevithan
Copy link
Owner

This is assumed to be fixed by v2.0.0, which added a CommonJS bundle.

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

3 participants