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

issue: react-hook-form bundle is different from other packages #11914

Closed
1 task done
Sh031224 opened this issue May 21, 2024 · 3 comments
Closed
1 task done

issue: react-hook-form bundle is different from other packages #11914

Sh031224 opened this issue May 21, 2024 · 3 comments

Comments

@Sh031224
Copy link

Sh031224 commented May 21, 2024

Version Number

7.51.4

Codesandbox/Expo snack

https://github.com/Sh031224/react-hook-form-bundle

Steps to reproduce

  1. git clone https://github.com/Sh031224/react-hook-form-bundle.git
  2. cd react-hook-form-bundle
  3. pnpm install && pnpm run dev
  4. Check React Dev tools > Components > Anonymous
  5. source is dist/index.cjs.js?:1

Expected behaviour

All packages must use esm.

What browsers are you seeing the problem on?

If you look at the source section with the Components tool of the react dev tool, only react-hook-form uses the commonjs bundle.

I think this issue is related. #8281

Therefore, when creating a package that includes react-hook-form as a peer dependency, context problems occur because esm and cjs are viewed differently.

스크린샷 2024-05-21 오후 7 23 15
스크린샷 2024-05-21 오후 7 23 50
스크린샷 2024-05-21 오후 7 24 16

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bluebill1049
Copy link
Member

bluebill1049 commented May 21, 2024

@Sh031224
Copy link
Author

Sh031224 commented May 21, 2024

@bluebill1049 However, if I change the exports field in the local environment as follows, it works normally.

"exports": {
    "./package.json": "./package.json",
    ".": {
      "types": "./dist/index.d.ts",
      "react-server": "./dist/react-server.esm.mjs",
      "import": "./dist/index.esm.mjs",
+      "module": "./dist/index.esm.mjs",
      "require": "./dist/index.cjs.js"
    }
image
{
  "dependencies": {
    "react-hook-form": "file:./react-hook-form",
  },
}

I added the above example to the repository.

  1. git clone https://github.com/Sh031224/react-hook-form-bundle.git
  2. sh ./prepare.sh && pnpm run dev

@Sh031224
Copy link
Author

Sh031224 commented May 22, 2024

https://webpack.js.org/guides/package-exports/#conditions

Because of support in webpack, it seems that module must also be added to the exports field.

also related: https://github.com/orgs/react-hook-form/discussions/3894#discussioncomment-2135181

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants