Browse Source

Suppress webpack's critical dependency warnings for libheif

Supressing it for now since it obscures other important information in the console.

Upstream issue, which currently doesn't have a workaround:
https://github.com/catdad-experiments/libheif-js/issues/23

Full error message:

     ⚠ ../../node_modules/libheif-js/libheif-wasm/libheif-bundle.js
    Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

    Import trace for requested module:
    ../../node_modules/libheif-js/libheif-wasm/libheif-bundle.js
    ../../node_modules/libheif-js/wasm-bundle.js
    ../../node_modules/heic-decode/index.js
    ../../node_modules/heic-convert/index.js
    ./src/worker/convert.worker.ts
    ./src/utils/comlink/ComlinkConvertWorker.ts
    ./src/services/heic-convert/service.ts
    ...

Refs:
- https://stackoverflow.com/questions/38392697/webpack-umd-critical-dependency-cannot-be-statically-extracted
Manav Rathi 1 year ago
parent
commit
9eab93cfdf
1 changed files with 11 additions and 1 deletions
  1. 11 1
      web/packages/next/next.config.base.js

+ 11 - 1
web/packages/next/next.config.base.js

@@ -59,11 +59,21 @@ const nextConfig = {
         GIT_SHA: gitSHA(),
     },
 
-    // https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j
+    // Customize the webpack configuration used by Next.js
     webpack: (config, { isServer }) => {
+        // https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j
         if (!isServer) {
             config.resolve.fallback.fs = false;
         }
+
+        // Suppress the warning "Critical dependency: require function is used
+        // in a way in which dependencies cannot be statically extracted" when
+        // import heic-convert.
+        //
+        // Upstream issue, which currently doesn't have a workaround.
+        // https://github.com/catdad-experiments/libheif-js/issues/23
+        config.ignoreWarnings = [{ module: /libheif-js/ }];
+
         return config;
     },
 };