-
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 .cjs and .mjs files support #535
Comments
Workaround for metro deficiency: facebook/metro#535 Caused by stylis shipping a .cjs file: thysultan/stylis#233 Fix from emotion-js/emotion#1986
Workaround for metro deficiency: facebook/metro#535 Caused by stylis shipping a .cjs file: thysultan/stylis#233 Fix from emotion-js/emotion#1986
I wanted to chime in and mention how I worked around this currently with RN 0.65.1
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const defaultSourceExts =
require('metro-config/src/defaults/defaults').sourceExts;
module.exports = {
transformer: {
getTransformOptions: () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
resolver: {
sourceExts: process.env.RN_SRC_EXT
? [...process.env.RN_SRC_EXT.split(',').concat(defaultSourceExts), 'cjs'] // <-- cjs added here
: [...defaultSourceExts, 'cjs'], // <-- cjs added here
},
}; The latest version of @apollo/client (3.5.2) is using |
How do I resolve this using expo?. I am using expo w/ typescript & I have no metro.config. any ideas on how to go about this? |
https://docs.expo.dev/guides/customizing-metro/
|
Thanks works great. Now I'm having another error. ReferenceError: Can't find variable: indexedDB |
Does React-Native even support IndexedDB? You should research this away from this page as it's not relevant to this topic. |
if anyone will encount problem with react navigation on react native:
This answer will help you too! Thanks @rossmartin |
I ran into an issue with firebase session persistence on React Native where it would not persist the auth session with the default fix of
@vladimirevstratov 's solution above
Fixed that issue |
This solution : doesn't solve it all I still get some errors like: here is a link to a simple gist that shows my dependencies and component |
I solved it like this for now: // metro.config.js
const { getDefaultConfig } = require('@expo/metro-config');
const defaultConfig = getDefaultConfig(__dirname);
module.exports = (async () => {
...
defaultConfig.resolver.sourceExts.push('cjs');
...
return defaultConfig;
})(); |
This issue is resolved in c1c6d9c which should ship in the next major release (0.72.0) 🙂.
|
Do you want to request a feature or report a bug?
bug
What is the current behavior?
If you have
require('./index.cjs')
you will have issue:If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can
yarn install
andyarn test
.lib.cjs
index.js
withrequire('./lib.cjs')
What is the expected behavior?
Load
.cjs
files as any.js
files.Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
Extra details
I opened this issue because users of my dual CJS/ESM project have a problem with using my lib to React Native
ai/nanoevents#44 (comment)
You had
.mjs
issue before, but it was closed because in 2017 it was not clear about.mjs
standard. Now.mjs
and.cjs
is an official Node.js API.The text was updated successfully, but these errors were encountered: