Repository navigation
Support ES Module / Typescript config #916
Description
Activity
- added a commit that references this issue
on Jul 7, 2023 Update on ESM configs:
In the other issue @robhogan mentioned that ESM configs will need to wait until Node.js v20 is used for the
react-nativeprojects:Now that we have ESM support for react-native.config files how about metro.config?
Reacted by Kræn HansenReacted by Kutsan Kaplan, Connor Black, Arya Emami, Dániel Földi and Ridwan IkhsanIs this being reconsidered now?
Any update?
I ran into this problem today as well. All files apart from this are now in ESM format, so this is quite frustrating having to find a workaround for.
Reacted by Kræn HansenAny update on this?
Metro now supports ESM and TS (requires Node 22+) configs, I still need to update the docs.
Reacted by lin72h and Floyd KimReacted by Karl Horky and RoyReacted by Karl Horky and Ridwan IkhsanMetro now supports ESM and TS (requires Node 22+) configs, I still need to update the docs.
How to enable? I have 0.83.3 but still this error
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); /** * Metro configuration * https://reactnative.dev/docs/metro * * @type {import('@react-native/metro-config').MetroConfig} */ const config = {}; module.exports = mergeConfig(getDefaultConfig(__dirname), config);@Master-Antonio we’re talking about the config file itself being ESM or TypeScript (eg
metro.config.mts). I’m not sure what you’re trying to do there, but please open a separate issue.Metro now supports ESM and TS (requires Node 22+) configs, I still need to update the docs.
@robhogan Can you update the docs accordingly?
Why does
resolveRequestnot exist onconfig.resolver(expo 54.0.32)?https://docs.expo.dev/versions/latest/config/metro/
// Doesn't exist on config type from // import { getDefaultConfig } from 'expo/metro-config'; // const config = getDefaultConfig(__dirname); config.resolver.resolveRequest = (context, moduleName, platform) => {
With the esm or ts config,
expo/metro-confignow needs to be imported with the js extension because there are no package.json exports for expo, and node esm requires extensions for file imports.- import { getDefaultConfig } from "expo/metro-config"; + import { getDefaultConfig } from "expo/metro-config.js";
Would be nice if the exports field could be added to the expo package.json so that we can go back to importing with just
expo/metro-config.Reacted by Mikael FinstadWould be nice if the exports field could be added to the expo package.json
@stevezhu sounds like a great candidate for a PR 😉💙
Reacted by Steve Zhu, Quim T. and Rob HoganClosing as done - ESM and TypeScript configs shipped in Metro 0.83.2, and the docs now cover the supported filenames and the Node version requirements.
@dominicinkfnd that's a separate question about Expo's config types rather than this issue - please raise it at https://github.com/expo/expo if it's still happening.
Reacted by Roy@robhogan thanks! I opened a PR to Expo docs updating the
metro.config.tsTypeScript documentation too:Reacted by Rob Hogan
Feature request: support typescript / esm config
What is the current behavior?
Metro does not look for a
metro.config.ts, and if it did, I have no idea whether it would be configurable as a module.This seems necessary sooner or later, as the ecosystem is moving to modules, and majority of people are using typescript (RN just made it the default for new projects).
What is the desired behavior?
Metro uses
metro.config.tsif it exists, and the docs include an example of what this looks like.