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

Compatibility with React Native #2

Closed
thgh opened this issue Jul 10, 2022 · 2 comments
Closed

Compatibility with React Native #2

thgh opened this issue Jul 10, 2022 · 2 comments

Comments

@thgh
Copy link

thgh commented Jul 10, 2022

React Native doesn't like .cjs, so it gives this error:

Android Bundling failed 334ms
While trying to resolve module `@joebobmiles/y-react` from file `/Users/.../App.tsx`, the package `/Users/.../node_modules/@joebobmiles/y-react/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/.../node_modules/@joebobmiles/y-react/dist/y-react.cjs`. Indeed, none of these files exist:

  * /Users/.../node_modules/@joebobmiles/y-react/dist/y-react.cjs(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)

An extra build output in rollup.config.js could resolve this.

@joebobmiles
Copy link
Owner

If you read rollup.config.js, you will see that cjs and mjs versions are already built and should be shipped in the package.

From what I can tell from the output you posted, React Native has choked on the main parameter in the package.json. this may be because:

  1. The package does not make use of the type parameter, or
  2. React Native does not respect the exports parameter during build time.

Are you using a transpiler such as Babel or TypeScript? Can you post a repo that reproduces this issue?

@joebobmiles
Copy link
Owner

Reviewing this while I'm not trying to fall asleep and doing a little research, it seems that React Native is expecting main to point to a non-compiled file (i.e. not cjs or mjs). It appears this is a known issue that Metro contributors are too busy/lazy to fix, since its two years old at this point and they closed 56 issues and 141 PRs in that time.

That being said, there are two work arounds, one being posted last night. I am going to close this issue and ask that you bother the Metro folks.

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