IjzerenHein / react-native-bundle-visualizer

See what packages are increasing your react-native bundle size 📦
MIT License
1.46k stars 44 forks source link

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). #112

Closed LinFeiLong closed 1 year ago

LinFeiLong commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-bundle-visualizer@3.1.1 for the project I'm working on.

This is a fix proposal to this issue https://github.com/IjzerenHein/react-native-bundle-visualizer/issues/38

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v18.0.0

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-bundle-visualizer/src/react-native-bundle-visualizer.js b/node_modules/react-native-bundle-visualizer/src/react-native-bundle-visualizer.js
index 6487b5c..5d1fb35 100755
--- a/node_modules/react-native-bundle-visualizer/src/react-native-bundle-visualizer.js
+++ b/node_modules/react-native-bundle-visualizer/src/react-native-bundle-visualizer.js
@@ -169,7 +169,7 @@ bundlePromise
       result.bundles.forEach((bundle) => {
         Object.keys(bundle.files).forEach((file) => {
           console.log(
-            chalk.green(file + ', size: ' + bundle.files[file] + ' bytes')
+            chalk.green(file + ', size: ' + bundle.files[file].size + ' bytes')
           );
         });
       });
@@ -188,4 +188,5 @@ bundlePromise

     // Open output file
     return open(bundleOutputExplorerFile);
-  });
+  })
+  .catch((error) => { });

This issue body was partially generated by patch-package.

hurali97 commented 1 year ago

Hi @LinFeiLong !

Thanks for providing the info. The error you're facing and the issue you mentioned, it happens on node version 18. A couple of days ago we fixed this here. We will be releasing a newer version of this package shortly which will fix this. 🙂