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

require function is used in a way in which dependencies cannot be statically extracted #23

Open
swissspidy opened this issue Jan 7, 2024 · 6 comments

Comments

@swissspidy
Copy link

Webpack is emitting this warning when I require( 'libheif-js/wasm-bundle' ) in my project.

The contents of wasm-bundle.js:

module.exports = require('./libheif-wasm/libheif-bundle.js')();

Not sure how this can be best addressed, I'd have to look into that, but I thought I'd share it here just in case in case anyone has ideas.

@ashuvssut
Copy link

ashuvssut commented Mar 31, 2024

This solution worked for me:

i changed the import statement like so:-

image

EDIT

@swissspidy ah sorry. its a bad solution

The warning went away. but the heic to jpeg conversions were failing. its a no-go

mnvr added a commit to ente-io/ente that referenced this issue Apr 15, 2024
Supressing it for now since it obscures other important information in the console.

Upstream issue, which currently doesn't have a workaround:
catdad-experiments/libheif-js#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
@catdad
Copy link
Member

catdad commented May 14, 2024

I am not all that familiar with this issue in particular -- it's been a while since I used webpack.

One question I have is: this shows as a warning. Warnings don't typically fail the build? Is this failing in some way or just causing annoying noise? I am finding that there are ways to ignore known warnings causing me to think this is not actually a blocking problem / failure as much as just scary looking.

Second question: I believe statically extracting dependencies has to do with treeshaking. Is that correct? This module can't really be slimmed down, since it doesn't include anything that is used.

Finally, it seems a few folks have reported it. Does anyone have a repro? Sharing a minimal code sample that reproduces the issue is very helpful in getting an issue debugged.

@jocluzet
Copy link

jocluzet commented May 14, 2024

If it helps, I have this error with version ^1.17.1 but not with 1.10.0. I use the program very simply as a dependency of heic-convert.

@ashuvssut
Copy link

ashuvssut commented May 14, 2024

Is this failing in some way or just causing annoying noise?

its not blocking anything. its just a noise in devtools console tab

btw thankyou for your awesome work! i tried other different libs but failed miserably. But libheif-js works nicely

@sagarchoudhary96
Copy link

Found the way to supress this critical dependency warninig: check it out here

@sdkawata
Copy link

@catdad

It appears that the issue can be reproduced simply by requiring it in webpack as follows.
To reproduce, you can clone the repository below, run npm install, and then npm run build:
https://github.com/sdkawata/webpack-libheif-js-23

It seems that the issue lies in the part where crypto is being required.
By specifying crypto as an external dependency like below,
the warning no longer appears for us:
https://github.com/catdad-experiments/libheif-js/compare/master...sdkawata:libheif-js:add_crypto_as_external_dependency?expand=1

Although this is a warning and not an error,
in our environment — where we use Create React App — CI halts on warnings.
We believe this issue may be related to our setup with Create React App,
and due to this, we are currently unable to introduce the library.
It would be greatly appreciated if you could fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants