Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ESM in react-native.config #2453

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

szymonrybczak
Copy link
Collaborator

Summary:

Closes #2167

Add support for ESM inside react-native.config file.

Test Plan:

  1. Clone the repository and do all the required steps from the Contributing guide
  2. Create a new project and add type: "module" inside package ✅
  3. Create a react-native.config.mjs with following content
export default {
  commands: [
    {
      name: 'hello',
      func: () => {
        console.log('hello esm');
      },
    },
  ],
};
  1. Run npx react-native hello and you should see hello esm log.

Checklist

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md

@satya164
Copy link
Member

satya164 commented Jul 11, 2024

Re: test plan, test these scenarios:

  • Add type: 'module' to package.json and use require in react-native.config.js - should fail unless using createRequire helper (import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);)
  • Add type: 'module' to package.json and use require in react-native.config.cjs
  • Add type: 'module' to package.json and use import/export in react-native.config.js
  • Remove type: 'module from package.json/add type: 'commonjs' and use import/export in react-native.config.mjs

You don’t need both type: 'module' and .mjs. either is enough to signal ES modules.

@szymonrybczak szymonrybczak force-pushed the feat/support-esm-in-react-native-config.js branch from 87e5843 to 6f0db32 Compare August 30, 2024 19:54
@szymonrybczak szymonrybczak force-pushed the feat/support-esm-in-react-native-config.js branch from 566877e to 0a7e8bf Compare August 31, 2024 09:25
@szymonrybczak szymonrybczak force-pushed the feat/support-esm-in-react-native-config.js branch from c670360 to 7f9a335 Compare August 31, 2024 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ESM react-native.config files
4 participants