-
Notifications
You must be signed in to change notification settings - Fork 626
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
Add support for .mjs and .cjs file extensions #770
Conversation
@GijsWeterings has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@GijsWeterings thank you for importing this! It seems like some internal build is failing, is there anything that I could help with? |
Hi @LinusU - the test failure was unrelated - apologies for the delay. We're discussing a slightly different approach here because currently adding to
Only the first is necessary in this case, because We're going to tweak the config format here to allow options for each extension (so we can have 1. without 2.) - something like |
This sounds great 👍
Not at all, that would be super! 👏 |
I'm not sure if this is the best place to ask this question, but in the hopes it might save someone else considerable time debugging, I'll ask. We recently added Somehow, it was detecting that we were in a web environment 🤷 Any idea what in the Anyways, sorry if this isn't the place for this discussion. |
If you are using expo, to resolve this issue, create a metro.config.js file in the project root. In the file add the file extension const { getDefaultConfig } = require("@expo/metro-config");
const defaultConfig = getDefaultConfig(__dirname);
defaultConfig.resolver.assetExts.push("cjs");
module.exports = defaultConfig; |
@huntie that's awesome! I'm glad to hear it 🎉 |
Summary
Node.js have added support for the
.mjs
and.cjs
extensions which many packages have started using. This pull request adds these two file extensions so that packages using them can still be loaded with Metro.This was specifically prompted by
@apollo/client
, a popular package that can be used from React Native, changing the file extension to.cjs
which broke compatibility with Metro.Fixes #535
Fixes #59
Fixes #60
Test plan
In a temporary directory:
npx react-native@latest init TestSourceExts
cd TestSourceExts
npx react-native run-ios
yarn add @apollo/client graphql
import { ApolloProvider } from '@apollo/client'
to top ofapp.js
<App />
npx react-native run-ios
node_modules/metro-config/src/defaults/defaults.js
npx react-native run-ios