Skip to content

CommonJS requires break build #848

Closed
@hielsnoppe

Description

@hielsnoppe

Description

  1. I created a new project using pnpx create-react-native-library@latest.

  2. I ran yarn.

  3. I ran yarn example web, then this happened:

    Error [ERR_REQUIRE_ESM]: require() of ES Module /home/.../react-native-origami/example/node_modules/react-native-monorepo-config/index.js from /home/.../react-native-origami/example/metro.config.js not supported.
    Instead change the require of index.js in /home/.../react-native-origami/example/metro.config.js to a dynamic import() which is available in all CommonJS modules.
    Error [ERR_REQUIRE_ESM]: require() of ES Module /home/.../react-native-origami/example/node_modules/react-native-monorepo-config/index.js from /home/.../react-native-origami/example/metro.config.js not supported.
    Instead change the require of index.js in /home/.../react-native-origami/example/metro.config.js to a dynamic import() which is available in all CommonJS modules.
    at Object. (/home/.../react-native-origami/example/metro.config.js:3:29)

Packages

  • create-react-native-library
  • react-native-builder-bob

Selected options

During project creation, I chose "JavaScript library" as type:

✔ What type of library do you want to develop? › JavaScript library

I have not changed Bob's settings in package.json:

"react-native-builder-bob": {
  "source": "src",
  "output": "lib",
  "targets": [
    [
      "module",
      {
        "esm": true
      }
    ],
    [
      "typescript",
      {
        "project": "tsconfig.build.json"
      }
    ]
  ]
},

Link to repro

https://github.com/dancesport-one/react-native-origami

Environment

info Fetching system and libraries information...
System:
  OS: Linux 6.8 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
  CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  Memory: 19.79 GB / 31.24 GB
  Shell:
    version: 5.2.21
    path: /bin/bash
Binaries:
  Node:
    version: 20.11.1
    path: ~/.nvm/versions/node/v20.11.1/bin/node
  Yarn:
    version: 3.6.1
    path: ~/snap/code/176/.local/share/pnpm/yarn
  npm:
    version: 10.2.4
    path: ~/.nvm/versions/node/v20.11.1/bin/npm
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
Languages:
  Java:
    version: 21.0.7
    path: /usr/bin/javac
  Ruby:
    version: 2.7.4
    path: /home/.../.rvm/rubies/ruby-2.7.4/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: latest
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.2
    wanted: 0.79.2
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions