Skip to content

Commit

Permalink
Work around React Native / Metro refusing to load .cjs modules. (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed May 4, 2023
1 parent 8ca1108 commit ae5f874
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions shared/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { readFile, writeFile } from "fs/promises";

export const globals = {
__proto__: null,
tslib: "tslib",
Expand All @@ -22,6 +24,17 @@ export function build(input, output, format) {
sourcemap: true,
globals
},
...(output.endsWith(".cjs") ? { plugins: [
{ // Inspired by https://github.com/apollographql/apollo-client/pull/9716,
// this workaround ensures compatibility with versions of React Native
// that refuse to load .cjs modules as CommonJS (to be fixed in v0.72):
name: "copy *.cjs to *.cjs.native.js",
async writeBundle({ file }) {
const buffer = await readFile(file);
await writeFile(file + ".native.js", buffer);
},
},
]} : null),
};
}

Expand Down

0 comments on commit ae5f874

Please sign in to comment.