You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have require('./index.cjs') you will have issue:
Error: While trying to resolve module `lib` from file `project/index.js`, the package `project/node_modules/lib/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`project/node_modules/lib/index.cjs`. Indeed, none of these files exist:
* project/node_modules/lib/index.cjs(.native|.web.js|.native.js|.js|.web.json|.native.json|.json|.web.ts|.native.ts|.ts|.web.tsx|.native.tsx|.tsx)
* project/node_modules/lib/index.cjs/index(.native|.web.js|.native.js|.js|.web.json|.native.json|.json|.web.ts|.native.ts|.ts|.web.tsx|.native.tsx|.tsx)
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.
Create empty project
Add lib.cjs
Create index.js with require('./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.
No Metro config
Metro 0.59.0
Node 13.11.0
Yarn 1.22.4
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)
The latest version of @apollo/client (3.5.2) is using .mjs as the entry point of the package. The above change fixed the issue with the dep.
Reacted by Pavlo Tretiak, robschwitzer, najahbouriga, Piyush Santwani, Daniyar, Paul, Samson Akinfenwa , Daniel Śledź, Andreas Jacob, Paul Pop and 17 more
Reacted by robschwitzer, Paul Segura and KJONDIVE
Reacted by robschwitzer, Daniyar, Daniel Śledź, Paul Pop, Paul Segura and vladimirevstratov
Reacted by robschwitzer, James Edmonston, Nguyễn Lâm, Daniyar, Daniel Śledź, Paul Segura, Natalia and vladimirevstratov
Reacted by robschwitzer, Daniyar, Daniel Śledź, Paul Segura, William Gurzoni, vladimirevstratov and nativedev79
Reacted by ZHANZIXIAN, Sibelly Cavalcante, Ata Herrera, Nicholas Choo, Nil Portugués Calderó, Kaique Nunes, Mr Stanislaus, Isaac Hartung and Antony Kavoo
Reacted by Nil Portugués Calderó
Reacted by Nil Portugués Calderó
Reacted by Pablo Bernal, ZHANZIXIAN, ansmlc, Nil Portugués Calderó and Mr Stanislaus
The latest version of @apollo/client (3.5.2) is using .mjs as the entry point of the package. The above change fixed the issue with the dep.
if anyone will encount problem with react navigation on react native:
Error: While trying to resolve module `nanoid/non-secure` from file `node_modules/@react-navigation/core/lib/commonjs/useRegisterNavigator.js`, the package `node_modules/nanoid/non-secure/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/node_modules/nanoid/non-secure/index.cjs`. Indeed, none of these files exist:
Activity
Update metro config to support loading .cjs files
Update metro config to support loading .cjs files
rossmartin commentedon Nov 16, 2021
I wanted to chime in and mention how I worked around this currently with RN 0.65.1
metro.config.jsThe latest version of @apollo/client (3.5.2) is using
.mjsas the entry point of the package. The above change fixed the issue with the dep.ndukachukz commentedon Jan 19, 2022
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?
mchambaud commentedon Jan 19, 2022
https://docs.expo.dev/guides/customizing-metro/
ndukachukz commentedon Jan 19, 2022
Thanks works great. Now I'm having another error.
ReferenceError: Can't find variable: indexedDB
mchambaud commentedon Jan 19, 2022
Does React-Native even support IndexedDB?
You should research this away from this page as it's not relevant to this topic.
vladimirevstratov commentedon Mar 21, 2022
if anyone will encount problem with react navigation on react native:
This answer will help you too! Thanks @rossmartin
mobinni commentedon Apr 15, 2022
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
Ahmed-ao commentedon Apr 23, 2022
This solution :
const { getDefaultConfig } = require("metro-config");
const { resolver: defaultResolver } = getDefaultConfig.getDefaultValues();
exports.resolver = {
...defaultResolver,
sourceExts: [
...defaultResolver.sourceExts,
"cjs",
],
};
doesn't solve it all I still get some errors like:
[TypeError: undefined is not a function (near '...graphql.parse...')]
https://gist.github.com/Ahmed-ao/69653660b03660cc94c7830b3bfbc8f9
here is a link to a simple gist that shows my dependencies and component
bombillazo commentedon Jul 11, 2022
I solved it like this for now:
huntie commentedon Jul 28, 2022
This issue is resolved in c1c6d9c which should ship in the next major release (0.72.0) 🙂.
.cjsand.mjsextensions by default when imported explicitly (import/requirethat includes the module file extension).watcher.additionalExtsoption..cjsand.mjsfiles implicitly (without giving the extension) can still be configured viaresolver.sourceExts.Add watcher.additionalExts option, enable inclusion of .cjs and .mjs …