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

__dirname is not sufficient to derive the path to WASM file #624

Closed
mPaella opened this issue May 9, 2023 · 5 comments
Closed

__dirname is not sufficient to derive the path to WASM file #624

mPaella opened this issue May 9, 2023 · 5 comments

Comments

@mPaella
Copy link

mPaella commented May 9, 2023

Problem

The compiled lib uses __dirname to resolve the path to cardano_serialization_lib_bg.wasm file, which does not always resolve correctly. Causing Error: ENOENT: no such file or directory, open '/project/sandbox/.next/server/app/foo/cardano_serialization_lib_bg.wasm'

Reproduction

https://codesandbox.io/p/sandbox/gifted-einstein-mo56ss?file=%2Fnext.config.js%3A19%2C7

  • View the code sandbox
  • See that both the app dir and pages dir are being used, and are calling the same function
  • Browse to /. See that the page loads
  • Browse to /foo. See that the page errors, due to incorrectly deriving the path to the WASM file

Fix?

As a hack to see if i could fix it, I tried editing the compiled files for @emurgo/cardano-serialization-lib under node_modules.

OLD - Not working - line ~14053 in the compiled code

const path = require('path').join(__dirname, 'cardano_serialization_lib_bg.wasm');

NEW - Working

const path = require('path').join(process.cwd(), "node_modules", "@emurgo", "cardano-serialization-lib-nodejs", 'cardano_serialization_lib_bg.wasm');
@mPaella
Copy link
Author

mPaella commented May 9, 2023

This appears to be a problem with wasm-pack actually, ill bring it up over there

@lisicky
Copy link
Contributor

lisicky commented May 10, 2023

Hi @mPaella ! Why did you choose the node csl version and not the browser version ?

@mPaella
Copy link
Author

mPaella commented May 10, 2023

@lisicky I'm using @blockfrost/blockfrost-js which uses the node package.

Which i'm pretty confident is correct, as the code isn't being run in the browser.

If you are familiar with NextJs, in the reproduction you will see that the code is being run inside getServerSideProps (working correctly, pages directory, node env), as well as inside the async server component (NOT working, app directory, still node env)

@lisicky
Copy link
Contributor

lisicky commented May 19, 2023

Thanks for clarification @mPaella ! It's better to create issue in Wasm-pack or next.js repo. Because it is issue of third-party tool

@lisicky
Copy link
Contributor

lisicky commented Jun 20, 2023

Seems it was done by vercel/next.js#49783

@lisicky lisicky closed this as completed Jun 20, 2023
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

2 participants