saasquatch / bunshi

Molecule pattern for jotai, valtio, zustand, nanostores, xstate, react and vue
https://www.bunshi.org/
MIT License
232 stars 17 forks source link

`react/bunshi` import incompatible with React Native #41

Open dmitriy-saltovskiy opened 10 months ago

dmitriy-saltovskiy commented 10 months ago

I tried to use it with React Native but got a warning and an error: warning:

warn Package bunshi has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in path/node_modules/bunshi/package.json

error:

error: Error: Unable to resolve module bunshi/react from some path: bunshi/react could not be found within the project or in these directories:
  node_modules
  ../node_modules

Looks like it connected to that issue https://github.com/react-native-community/cli/issues/1168

caltikoc commented 10 months ago

These warnings and errors often occur due to invalid or missing configurations within the package.json file of the package being used. To resolve these issues, follow these steps:

  1. Check Package Configuration:

    • Open the package.json file within the bunshi package and ensure that the exports section defines the specified subpath or module, such as './package.json'.
  2. Reinstall Dependencies in Your Project:

    • Errors are often caused by incomplete or incorrectly installed packages. Therefore, in your project directory, run npm install or yarn install in a command prompt to reinstall dependencies.
  3. Update the Package Version:

    • If possible, try using an updated version of the bunshi package. Newer versions might resolve these kinds of issues.
  4. Explore Alternative Solutions:

    • Search forums, GitHub issues, or platforms like Stack Overflow for experiences and solutions shared by others encountering similar problems. These resources might offer solution suggestions from individuals who have faced similar issues.

After attempting these steps, if the issue persists, consider analyzing the error message in more detail or seeking help from sources where you can find more specific information or guidance related to this error.

loganvolkers commented 10 months ago

Thanks for the bug report @dmitriy-saltovskiy and for the resolution steps @caltikoc

I would love to see support for React Native better tested and documented.

Would either of you be open to contributing a PR with the fix and some other React Native improvements?

kaladivo commented 10 months ago

This is because metro does not support exports in package.json yet. But it is in beta. See this.

For me, the simplest fix was to simply import the package from bunshi/dist/react.

It should be fixed in next versions of react-native...

loganvolkers commented 10 months ago

Thanks for clarifying and linking out to the relevant resources @kaladivo

It might still be possible to fix this issue by changing the build and deploy process to move files from dist into the root folder. I believe that jotai uses this trick.

In the meantime:

A few possible tasks for the community to tackle if anyone is keen:

sunniejai commented 1 day ago

Hi there, any update on this issue? Seems like package exports is not supported in React native?