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

@react-native/metro-config doesn't export default assetExts and sourceExts anymore. #38069

Closed
gvarandas opened this issue Jun 26, 2023 · 4 comments
Labels
Needs: Triage 🔍 Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@gvarandas
Copy link
Contributor

gvarandas commented Jun 26, 2023

Description

While upgrading to 0.72.0, we've noticed that the default config exported by @react-native/metro-config doesn't contain default values for the assetExts and sourceExts options, making it harder to extend those values in case projects need to perform any custom configuration.

A common use-case for extending these configs would be to better support svg files to be transpiled as React components (think of react-native-svg).

const { resolver: {sourceExts, assetExts} } = await getDefaultConfig();
// ...
resolver: {
  assetExts: assetExts.filter(ext => ext !== 'svg'),
  sourceExts: [...sourceExts, 'svg', 'cjs', 'mjs'],
},

It seems like this regression was caused due to dropping merging the original Metro config with the RN one (on this commit).

Is this a legit regression or do we expect projects to tap into metro-config directly to read those default values (maybe via loadConfig)?

Happy to provide a PR fixing the issue if it's flagged as a unintended behaviour.

React Native Version

0.72.0

Output of npx react-native info

  OS: macOS 13.4
  CPU: (8) arm64 Apple M1 Pro
  Memory: 115.80 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.3.1
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 9.6.7
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.06.12.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.11.3
    path: /Users/gvarandas/.gem/ruby/3.1.2/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK:
    API Levels:
      - "24"
      - "25"
      - "26"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
    Build Tools:
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
    System Images:
      - android-29 | Google APIs ARM 64 v8a
      - android-29 | Google APIs Intel x86 Atom
      - android-29 | Google APIs Intel x86 Atom_64
      - android-31 | Google APIs ARM 64 v8a
      - android-31 | Google APIs Intel x86_64 Atom
      - android-31 | Google Play ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2022.1 AI-221.6008.13.2211.9619390
  Xcode:
    version: 14.3/14E222b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.15
    path: /usr/bin/javac
  Ruby:
    version: 3.1.2
    path: /opt/rubies/3.1.2/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.0
    wanted: 0.72.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to reproduce

  • Install 0.72.0
  • Install all dependencies (yarn, npm i, etc)
  • Check that the output from getDefaultConfig (@react-native/metro-config) doesn't produce the following structure anymore:
resolver: {
  assetExts: [ /* values */],
  sourceExts [ /* values */],
},

Snack, code example, screenshot, or link to a repository

Any new project is capable of checking for this issue.
The code present in the Upgrade Helper would reproduce the issue consistently.

@abgaryanharutyun
Copy link

Hey @gvarandas this is not related to react native configuration just check this comment fromreact-native-svg-transformer
kristerkari/react-native-svg-transformer#276 (comment)

@Pranav-yadav Pranav-yadav added Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. Impact: Misconfiguration When the issue is due to a misconfig for the user and removed Impact: Misconfiguration When the issue is due to a misconfig for the user labels Jun 27, 2023
@cortinico
Copy link
Contributor

cc @huntie

@huntie
Copy link
Member

huntie commented Jun 27, 2023

@react-native/metro-config is distinct from the metro-config package. Please see this answer: facebook/metro#1010 (comment).

Closing as duplicate.

@huntie huntie closed this as completed Jun 27, 2023
huntie added a commit to huntie/react-native that referenced this issue Jun 27, 2023
Summary:
Reverts facebook#36777.

This is motivated by reducing user friction when the widespread assumption is for `react-native/metro-config` to export a complete Metro config, as with Expo/rnx-kit, and like previously understood uses of `metro-config`. See facebook/metro#1010 (comment) for further notes.

Fixes:
- facebook/metro#1010
- facebook#38069
- kristerkari/react-native-svg-transformer#276

Note that we do not intend for `react-native/metro-config` to directly export `assetExts` etc — these can be accessed on the `resolver` property from the full config object.

Changelog: [General][Changed] `react-native/metro-config` now includes all base config values from `metro-config`

Differential Revision: D47055973

fbshipit-source-id: 78b59d925be72aa42b4b9d901c6f8d174f2dbae0
huntie added a commit to huntie/react-native that referenced this issue Jun 28, 2023
Summary:
Pull Request resolved: facebook#38092

Reverts facebook#36777.

This is motivated by reducing user friction when the widespread assumption is for `react-native/metro-config` to export a complete Metro config, as with Expo/rnx-kit, and like previously understood uses of `metro-config`. See facebook/metro#1010 (comment) for further notes.

Fixes:
- facebook/metro#1010
- facebook#38069
- kristerkari/react-native-svg-transformer#276

Note that we do not intend for `react-native/metro-config` to directly export `assetExts` etc — these can be accessed on the `resolver` property from the full config object.

Changelog: [General][Changed] `react-native/metro-config` now includes all base config values from `metro-config`

Reviewed By: robhogan

Differential Revision: D47055973

fbshipit-source-id: eedc4698e651645ada46a013d3945a16965bff22
facebook-github-bot pushed a commit that referenced this issue Jun 28, 2023
Summary:
Pull Request resolved: #38092

Reverts #36777.

This is motivated by reducing user friction when the widespread assumption is for `react-native/metro-config` to export a complete Metro config, as with Expo/rnx-kit, and like previously understood uses of `metro-config`. See facebook/metro#1010 (comment) for further notes.

Fixes:
- facebook/metro#1010
- #38069
- kristerkari/react-native-svg-transformer#276

Note that we do not intend for `react-native/metro-config` to directly export `assetExts` etc — these can be accessed on the `resolver` property from the full config object.

Changelog: [General][Changed] `react-native/metro-config` now includes all base config values from `metro-config`

Reviewed By: robhogan

Differential Revision: D47055973

fbshipit-source-id: 5ad23cc9700397110de5c0e81c7d76299761ef0a
kelset pushed a commit that referenced this issue Jun 28, 2023
Summary:
Pull Request resolved: #38092

Reverts #36777.

This is motivated by reducing user friction when the widespread assumption is for `react-native/metro-config` to export a complete Metro config, as with Expo/rnx-kit, and like previously understood uses of `metro-config`. See facebook/metro#1010 (comment) for further notes.

Fixes:
- facebook/metro#1010
- #38069
- kristerkari/react-native-svg-transformer#276

Note that we do not intend for `react-native/metro-config` to directly export `assetExts` etc — these can be accessed on the `resolver` property from the full config object.

Changelog: [General][Changed] `react-native/metro-config` now includes all base config values from `metro-config`

Reviewed By: robhogan

Differential Revision: D47055973

fbshipit-source-id: 5ad23cc9700397110de5c0e81c7d76299761ef0a
@huntie
Copy link
Member

huntie commented Jun 29, 2023

This is being cherry picked into the upcoming React Native 0.72.1 release. Please make sure to upgrade @react-native/metro-config (to 0.72.1) in order to access resolver.sourceExts, resolver.assetExts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

No branches or pull requests

5 participants