-
Notifications
You must be signed in to change notification settings - Fork 928
Error: While trying to resolve module idb
#6253
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
Comments
I have the same issue using expo 44.0.0 and react-native 0.64.3, for now I have downgraded to 9.2.0 and that works for the time being. |
That is odd. Does Also, searching around, I found some issues with Metro recognizing CJS files and suggest adding |
I have the same issue, as already mentioned in the PR comments. Once upgraded to 9.8.0 or 9.8.1, the error pops up. Maybe related to facebook/metro#770 |
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; |
@SohelIslamImran Thanks, that resolved it for me :-) |
Thanks for the link. In light of this I think that the correct solution is probably that frameworks should be adding However, I'm not an expert in Metro or React Native so I'm open to other perspectives on it. |
I'm going to close this issue as it can be fixed by changing the Metro config. Feel free to let me know if there is anything the Firebase JS SDK should be doing on our end to help with this issue and I can reopen it. |
For me this issue was conflating with refactoring to the new version. |
I'm afraid this is still an issue. The metro bundler configuration allows for the .cjs file to be resolved. However, it appears that this file is not properly bundled and leads to another runtime error:
This error is thrown at https://github.com/firebase/firebase-js-sdk/blob/%40firebase/app%400.7.26/packages/app/src/indexeddb.ts#L37 function getDbPromise(): Promise<IDBPDatabase<AppDB>> {
if (!dbPromise) {
dbPromise = openDB<AppDB>(DB_NAME, DB_VERSION, { In the minified bundle this code looks like this: var _idb = _$$_REQUIRE(_dependencyMap[10], "idb");
// ...
function getDbPromise() {
if (!dbPromise) {
dbPromise = (0, _idb.openDB)(DB_NAME, DB_VERSION, { When debugging the code, My environment:
AssessmentThis is probably an issue with Metro bundler itself. Either that or the generated .cjs file of idb is wrong but at a first glance this does not seem to be an issue. Given that the Metro bundler version is already a bit older, this may have been fixed already. However, Expo wants to use that older version so I suppose they need to upgrade first. WorkaroundMetro bundler can actually process the idb/index.js file which is a native ES module. So as a workaround, the package.json file of idb can be modified so that In this case the custom metro configuration is not necessary at all. The change can be persisted by using patch-package and |
bump |
Can @mfellner report the suggested package.json fix to the idb repo (https://github.com/jakearchibald/idb) and see if the maintainer thinks it's a good fix, or if another fix can be done? Or can anyone else interested in this bug who has a good understanding of the Metro issue report it in that repo? Unfortunately if the fix needs to be done there, we can't do it. I can report it but I don't think I'm in as good of a position to explain what the deal is with Metro, or provide an example. |
Metro said they added support for CJS in July/August 2022 (facebook/metro#770) so I'm guessing this issue is fixed and the workaround shouldn't be needed anymore. Let me know if I'm wrong and I'll reopen this. |
TL;DR
I ended up downgrading the version in which the error is gone.
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
I'm trying to use the sdk v9.8.1 for a react native project.
I followed the instruction to setup firebase.
Looking at the error, it seems like some idb related resolving module issue but I don't really get what it is.
so I'm wondering if I'm missing some react native specific configuration.
I'd appreciate if you could let me know if I'm getting something wrong.
Thanks.
Steps to reproduce:
Relevant Code:
The text was updated successfully, but these errors were encountered: