Skip to content
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

Error: Cannot find module 'fs/promises' #5584

Closed
JaapWeijland opened this issue Aug 10, 2021 · 12 comments · Fixed by #5585
Closed

Error: Cannot find module 'fs/promises' #5584

JaapWeijland opened this issue Aug 10, 2021 · 12 comments · Fixed by #5585
Labels
help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report

Comments

@JaapWeijland
Copy link

JaapWeijland commented Aug 10, 2021

Issue

When installing @react-native-firebase/app via expo install @react-native-firebase/app, it throws the following error:

Error: Cannot find module 'fs/promises'

Steps to reproduce:

  • expo init (blank Typescript)
  • expo install expo-dev-client
  • expo run:ios (I did an intermediary test)
  • expo install @react-native-firebase/app @react-native-firebase/messaging @react-native-firebase/auth @react-native-firebase/perf @react-native-firebase/crashlytics

Output:

Cannot find module 'fs/promises'
Require stack:
- /Volumes/ExternalSSD/Work/WeijlandIT/Expo Firebase Starter/expo-firebase-starter/node_modules/@react-native-firebase/app/plugin/build/android/copyGoogleServices.js
- /Volumes/ExternalSSD/Work/WeijlandIT/Expo Firebase Starter/expo-firebase-starter/node_modules/@react-native-firebase/app/plugin/build/android/index.js
- /Volumes/ExternalSSD/Work/WeijlandIT/Expo Firebase Starter/expo-firebase-starter/node_modules/@react-native-firebase/app/plugin/build/index.js
- /Volumes/ExternalSSD/Work/WeijlandIT/Expo Firebase Starter/expo-firebase-starter/node_modules/@react-native-firebase/app/app.plugin.js
- /usr/local/lib/node_modules/expo-cli/node_modules/@expo/config-plugins/build/utils/plugin-resolver.js
- /usr/local/lib/node_modules/expo-cli/node_modules/@expo/config-plugins/build/plugins/withStaticPlugin.js
- /usr/local/lib/node_modules/expo-cli/node_modules/@expo/config-plugins/build/plugins/withPlugins.js
- /usr/local/lib/node_modules/expo-cli/node_modules/@expo/config-plugins/build/index.js
- /usr/local/lib/node_modules/expo-cli/node_modules/@expo/config/build/plugins/withConfigPlugins.js
- /usr/local/lib/node_modules/expo-cli/node_modules/@expo/config/build/Config.js
- /usr/local/lib/node_modules/expo-cli/node_modules/@expo/config/build/index.js
- /usr/local/lib/node_modules/expo-cli/build/commands/installAsync.js
- /usr/local/lib/node_modules/expo-cli/build/commands/install.js
- /usr/local/lib/node_modules/expo-cli/build/commands/index.js
- /usr/local/lib/node_modules/expo-cli/build/exp.js
- /usr/local/lib/node_modules/expo-cli/bin/expo.js

Project Files

Expo default. Did not change them manually.

Javascript

package.json:

"scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-firebase/app": "^12.4.0",
    "@react-native-firebase/auth": "^12.4.0",
    "@react-native-firebase/crashlytics": "^12.4.0",
    "@react-native-firebase/messaging": "^12.4.0",
    "@react-native-firebase/perf": "^12.4.0",
    "expo": "~42.0.1",
    "expo-dev-client": "^0.4.7",
    "expo-splash-screen": "~0.11.2",
    "expo-status-bar": "~1.0.4",
    "expo-updates": "~0.8.1",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "~0.63.4",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-reanimated": "~2.2.0",
    "react-native-screens": "~3.4.0",
    "react-native-unimodules": "~0.14.5",
    "react-native-web": "~0.13.12"
  },
  "devDependencies": {
    "@babel/core": "^7.9.0",
    "@types/react": "~16.9.35",
    "@types/react-native": "~0.63.2",
    "typescript": "~4.0.0"
  },
  "private": true,
  "name": "xxx",
  "version": "1.0.0"
}

app.json

{
  "expo": {
    "name": "xxx",
    "slug": "xxx",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "Weijland.IT.expo-firebase-starter"
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      }
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "plugins": [
      "@react-native-firebase/app",
      "@react-native-firebase/perf",
      "@react-native-firebase/crashlytics"
    ]
  }
}

Environment

Click To Expand

**Node --version: ** v12.14.0

react-native info output:

react-native is not installed.

@JaapWeijland JaapWeijland added help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report labels Aug 10, 2021
@JaapWeijland
Copy link
Author

Already fixed it. Problem was that I had node v12.14 installed, which does not seem to have the module fs/promises installed. Node v14 does, so I updated.

More info: nodejs/node#35740.

@mikehardy
Copy link
Collaborator

Interesting. I'm not sure that's a requirement that we have vs one that expo has, but one of us may be missing a minimum node version warning. I was under the impression react-native-firebase still worked on v12.

You can ask yarn why fs/promises to see who is pulling in fs/promises. If it's react-native-firebase we might need to mention somewhere we need node v14+

@barthap
Copy link
Contributor

barthap commented Aug 11, 2021

I think this happened because I recklessly used fs/promises to copy android google-services.json and totally forgot it was introduced in Node 14 🤦‍♂️

If we want to keep compatibility with Node 12, usage of await fs.copyFile() can be safely replaced with fs.copyFileSync() from "legacy" fs.

@mikehardy
Copy link
Collaborator

Indeed that represents an unexpected breaking change. If you have a minute for repair I'm in there working on release stuff today and can release

@barthap
Copy link
Contributor

barthap commented Aug 11, 2021

Opened a hotfix PR, but currently have no chance to test it locally now, but it should be ok

Noticed that fs.promises API is available since Node 10 (see nodejs/node#35740 and Node 12 docs) so I just modified the import

@mikehardy
Copy link
Collaborator

Merged! Thanks - will do a release today as I've just gotten the new AppCheck module finally ready. Fix will be in 12.5.0

@drtennan
Copy link

Hi, I was just wondering if you knew when the fs/promises fix in 12.5.0 will be released. Thank you!

@mikehardy
Copy link
Collaborator

mikehardy commented Aug 12, 2021

Looking to release it today - got hung up on an unexpected CI failure which meant I wasn't confident to release it yesterday, but my workday just started so it might be a little while - keep an eye out

@drtennan
Copy link

Thanks so much for the release! It looks like it's resolved for the android package. Unfortunately, after updating I still receive the error about fs/promises. It looks like it might need to be changed for the iOS file as well when copying GoogleService-Info.plist

Error: Cannot find module 'fs/promises'
Require stack:

  • /Users/drtennan/GitHub/app/node_modules/@react-native-firebase/app/plugin/build/iOS/appDelegate.js
  • ...

@barthap
Copy link
Contributor

barthap commented Aug 13, 2021

🤦‍♂️

As a hotfix, please apply this patch (download, then unzip the patches dir):
patches.zip using e.g. npx patch-package --patch-dir ./path/to_your/patches_directory

The patch itself:

diff --git a/node_modules/@react-native-firebase/app/plugin/build/ios/appDelegate.js b/node_modules/@react-native-firebase/app/plugin/build/ios/appDelegate.js
index ac79980..f9353fd 100644
--- a/node_modules/@react-native-firebase/app/plugin/build/ios/appDelegate.js
+++ b/node_modules/@react-native-firebase/app/plugin/build/ios/appDelegate.js
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.withFirebaseAppDelegate = exports.modifyObjcAppDelegate = void 0;
 const config_plugins_1 = require("@expo/config-plugins");
-const promises_1 = __importDefault(require("fs/promises"));
+const fs_1 = __importDefault(require("fs"));
 const methodInvocationBlock = `[FIRApp configure];`;
 function modifyObjcAppDelegate(contents) {
     // Add import
@@ -27,7 +27,7 @@ const withFirebaseAppDelegate = config => {
         'ios',
         async (config) => {
             const fileInfo = config_plugins_1.IOSConfig.Paths.getAppDelegate(config.modRequest.projectRoot);
-            let contents = await promises_1.default.readFile(fileInfo.path, 'utf-8');
+            let contents = await fs_1.default.promises.readFile(fileInfo.path, 'utf-8');
             if (fileInfo.language === 'objc') {
                 contents = modifyObjcAppDelegate(contents);
             }
@@ -35,7 +35,7 @@ const withFirebaseAppDelegate = config => {
                 // TODO: Support Swift
                 throw new Error(`Cannot add Firebase code to AppDelegate of language "${fileInfo.language}"`);
             }
-            await promises_1.default.writeFile(fileInfo.path, contents);
+            await fs_1.default.promises.writeFile(fileInfo.path, contents);
             return config;
         },
     ]);

I'll open another PR 🤦

@mikehardy
Copy link
Collaborator

I just merged that PR (thanks @barthap !) and I'm looking to do another release today (my day just started though...) so keep an eye out for 12.6.0 or 12.5.1 depending on whether I can get a new feature in or not...

@drtennan
Copy link

Thanks, @barthap and @mikehardy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants