Add exports entry point to support node's module resolution.
React admin provides cjs and esm bundles. However, it relies on main and module in the package.json file to decide which version to use. It will work with most bundlers but fails when using node's module resolution as it doesn't support the module field. I was hit with this problem when trying to test a component using vitest.
Example:
function ComponentA() {
return <SimpleForm><ComponentB /></SimpleForm>
}
function ComponentB() {
const { watch } = useFormContext()
return ...
}SimpleForm is loaded using cjs and uses FormProvider (cjs) from react-hook-form. ComponentB uses useFormContext from react-hook-form esm bundle and context will be null.
Describe the solution you'd like
Add exports to package.json specifying the entry points for import and require.
Additional context https://github.com/vitest-dev/vitest/discussions/4233 https://nodejs.org/api/packages.html#package-entry-points
Source: marmelab/react-admin