msgpackr icon indicating copy to clipboard operation
msgpackr copied to clipboard

Add support for react-native

Open steida opened this issue 9 months ago • 2 comments

This fixes msgpackr usage in react-native

diff --git a/package.json b/package.json
index 9216a6e3cb7bd14e9c2c57f579634cbfcb117c23..2b56a98ba0fd90faaf414139767a212872dda265 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
   "types": "./index.d.ts",
   "main": "./dist/node.cjs",
   "module": "./index.js",
+  "react-native": "./index.js",
   "keywords": [
     "MessagePack",
     "msgpack",

steida avatar Mar 16 '25 18:03 steida

Is there some documentation explains this (react native doesn't use the standard entry point specification?)?

kriszyp avatar Mar 16 '25 23:03 kriszyp

This is how I fixed msgpackr for RN. It wasn't working so there is no chance you will break anything :-) Metro docs. I think this is
a fix for CJS, but if you decide to support only ESM, then you will need this: https://github.com/ai/nanoid/issues/468#issuecomment-2727577346

steida avatar Mar 17 '25 08:03 steida

@kriszyp I can confirm the proposed change in package.json does work. React Native's runtime does not include Node standard libraries, resulting in a module resolution error since the main entrypoint is node.cjs.

For reference, Metro's (React Native's bundler) default module resolution order is:

  1. "react-native"
  2. "browser"
  3. "main"

Unfortunately, support for "exports" is not enabled by default and has been in experimental/unstable status for a long time.

unendingblue avatar Apr 18 '25 10:04 unendingblue