I was trying to import react-native inside a bun test, so I wrote a plugin to strip flow types from react-native packages, but when I import react-native the module get empty.
Create the plugin
// plugin.ts
import type { BunPlugin } from "bun";
import { plugin } from "bun";
import stripTypes from "flow-remove-types";
### What is the expected behavior?
React native should be imported correctly and the modules should be listed
### What do you see instead?
An empty module
<img width="961" alt="Screenshot 2024-04-08 at 16 39 28" src="https://github.com/oven-sh/bun/assets/30508218/7a2623a8-1d6a-40d4-8aff-141fcbee5b66">
### Additional information
When I try to use `require("react-native")` I get this:
TypeError: require() async module "/Users/carlos/Documents/Projetos/Javascript/bun-test-react-native/node_modules/react-native/index.js" is unsupported. use "await import()" instead.
What version of Bun is running?
1.1.2+c8d072c2a
What platform is your computer?
Darwin 23.4.0 arm64 arm
What steps can reproduce the bug?
I was trying to import
react-native
inside a bun test, so I wrote a plugin to strip flow types from react-native packages, but when I importreact-native
the module get empty.import { plugin } from "bun"; import stripTypes from "flow-remove-types";
function stripFlowTypesPlugin(): BunPlugin { return { name: "strip-flow-types", setup: (build) => { build.onLoad({ filter: /node_modules\/react-native.*.jsx?$/ }, async ({ path, loader }) => { console.log(
Processing ${path}
);}; }
await plugin(stripFlowTypesPlugin());
describe("Example", () => { it("should", async () => { const mod = await import("react-native") console.log(mod) // prints -> Module {} }) })
TypeError: require() async module "/Users/carlos/Documents/Projetos/Javascript/bun-test-react-native/node_modules/react-native/index.js" is unsupported. use "await import()" instead.