Skip to content
Compare
Choose a tag to compare
@satya164 satya164 released this 04 Apr 21:25
· 1 commit to main since this release
f1db236

0.40.0 (2025-04-04)

Important

There's a possibility of dual package hazard with the default setup. Metro enables exports support from 0.82.0, so this can become a problem for some packages.

This release drops the dual package setup from the default template in favor of an ESM-only setup. To make a similar change in your package, apply the following change to your entrypoints:

- "main": "./lib/commonjs/index.js",
+ "main": "./lib/module/index.js",
- "types": "./lib/typescript/commonjs/src/index.d.ts",
  "exports": {
    ".": {
-     "import": {
-       "types": "./lib/typescript/module/src/index.d.ts",
-       "default": "./lib/module/index.js"
-     },
-     "require": {
-       "types": "./lib/typescript/commonjs/src/index.d.ts",
-       "default": "./lib/commonjs/index.js"
-     }
+     "types": "./lib/typescript/src/index.d.ts",
+     "default": "./lib/module/index.js"
    },
    "./package.json": "./package.json"
  },

If you need to support legacy setups that use moduleResolution: node10 or moduleResolution: node, you can also keep the types field:

  "main": "./lib/module/index.js",
+ "types": "./lib/typescript/src/index.d.ts",

In addition, remove the commonjs target from the react-native-builder-bob field in your package.json or bob.config.js or bob.config.mjs:

"react-native-builder-bob": {
  "source": "src",
  "output": "lib",
  "targets": [
    ["module", { "esm": true }],
-   ["commonjs", { "esm": true }]
    "typescript",
  ]
}

You may also want to delete your output (e.g. lib) folder to cleanup the leftover commonjs build.

Alternatively, you can run npx react-native-builder-bob@latest init in your project and accept the default configuration to re-configure react-native-builder-bob with the above setup.

With this change, Jest will break for the consumers of your libraries due to the usage of ESM syntax. So they may need to update their Jest configuration to transform your library:

module.exports = {
  preset: 'react-native',
+ transform: {
+   'node_modules/(your-library|another-library)': 'babel-jest',
+ },
};

If consumers of your library are using it in NodeJS in a CommonJS environment, they'll need to use at least NodeJS v20.19.0 to be able to synchronously require your library.

You can read more at our ESM support docs.

Features