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

cardano_serialization_lib_bg.js includes a "require" #119

Closed
MarcelKlammer opened this issue Feb 12, 2021 · 11 comments
Closed

cardano_serialization_lib_bg.js includes a "require" #119

MarcelKlammer opened this issue Feb 12, 2021 · 11 comments

Comments

@MarcelKlammer
Copy link
Contributor

MarcelKlammer commented Feb 12, 2021

Thanks for this awesome lib.

The browser package includes a "require()" call in cardano-serialization-lib-browser/cardano_serialization_lib_bg.js

Would it be possible to get rid of that call? I have to comment out the whole function otherwise I see:

WARNING  Compiled with 1 warnings                                                                                                                                                                                                                                                                     5:01:36 PM

 warning  in ./src/utils/cardano-serialization-lib-browser/cardano_serialization_lib_bg.js

Critical dependency: the request of a dependency is an expression

ModuleDependencyWarning: Critical dependency: the request of a dependency is an expression
    at Compilation.reportDependencyErrorsAndWarnings (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1459:23)
    at /Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1258:10
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:20:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/tapable/lib/Hook.js:154:20)
    at Compilation.finish (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1253:28)
    at /Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compiler.js:672:17
    at eval (eval at create (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at /Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1185:12
    at /Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1097:9
    at processTicksAndRejections (node:internal/process/task_queues:75:11)
    at CommonJsRequireContextDependency.getWarnings (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/dependencies/ContextDependency.js:40:18)
    at Compilation.reportDependencyErrorsAndWarnings (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1454:24)
    at /Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1258:10
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:20:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/tapable/lib/Hook.js:154:20)
    at Compilation.finish (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1253:28)
    at /Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compiler.js:672:17
    at eval (eval at create (/Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at /Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1185:12
    at /Users/marcelklammer/Documents/workspaces/github/ccwallet/node_modules/webpack/lib/Compilation.js:1097:9
    at processTicksAndRejections (node:internal/process/task_queues:75:11)

Process finished with exit code 130 (interrupted by signal 2: SIGINT)
@SebastienGllmt
Copy link
Contributor

It's just a warning so it should be fine. The code you're referring to is automatically generated so it's not really practical to try and modify it all the time. The better solution would be to update to a wasm bindgen version that fixes this, but upgrading that caused the ASM.js package to fail to compile due to some other downstream issues. It looks like it may have finally been resolved (rustwasm/wasm-pack#886 (comment)) but I haven't looked into this yet

@MarcelKlammer
Copy link
Contributor Author

I do it manually for now, no problem. If it would be just a warning I wouldn't post it here. It actually causes the compiler to fail, at least for me.

So yeah. All good for now.

@SebastienGllmt
Copy link
Contributor

For Yoroi we use both the nodejs and the browser bindings just fine so maybe you have an issue in your setup code https://github.com/Emurgo/yoroi-frontend

@brendansiraky
Copy link

MarcelKlammer

I'm running into the same issue, can you please tell me where in this file is causing that error so I can also comment it out. It's a very big file, i'm not entirely sure where this is being caused from. Thanks in advance

@MarcelKlammer
Copy link
Contributor Author

Search for

require(

there are two lines with that string, one reads

module.require(

the other one reads

require(

Add

module.

then you are good to go.

@brendansiraky
Copy link

Legend! Thanks so much for such a quick reply. Been scratching my head for 2 days trying to work this out.

@brendansiraky
Copy link

MarcelKlammer

Your answer worked for when I can comment it out directly in the file, which is good when running this locally.
But when I am pushing this to some live server that is doing the package downloading on build (npm install), this problem persists as it does not have the my commented out changes.
Do you have another idea of how to fix this ?
Thanks for your help.

@MarcelKlammer
Copy link
Contributor Author

I do compile the web target myself, so it's not a dependency in a package.json, but rather a file that gets transpiled into the final app.

@brendansiraky
Copy link

How did you manage to do this?

@Innocent-Akim
Copy link

#./src/cardano/serialization-lib/@emurgo/cardano-serialization-lib-browser/cardano_serialization_lib_bg.wasm Échec de l'analyse du module : l'en-tête magique n'est pas détecté Le fichier a été traité avec les chargeurs suivants: * ./node_modules/file-loader/dist/cjs.js Vous aurez peut-être besoin d'un chargeur supplémentaire pour gérer le résultat de ces chargeurs. Erreur: en-tête magique non détecté

@dduehr
Copy link

dduehr commented Jan 5, 2023

The warning still shows up with the most recent version 11.2.1 (2022-12-19 14:27:46).

As a workaround, I temporarily added a webpack "ignoreWarnings" object for the module "@emurgo/cardano-serialization-lib-browser/cardano_serialization_lib_bg.js" (regex) to my project. But Sebastiens solution would still be the best.

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

5 participants