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
Issue running ergo-lib-wasm-browser
in Node environments
#632
Comments
Thanks for bringing this up! |
Sure. I can add the official Node standard Which one do you think is better to implement? |
Thanks for picking it up! I don't know that much about the ecosystem so I leave it up to you. I'm not sure if wasm-pack PR gets merged at all. I'd prefer the method that does not affect/brake the browser workflow. |
Ok. I work on it and create a PR asap. |
Another possible option could be using the node package in tests and the browser package in browser - since I've done something like this in the past, and I think I've seen some other projects do something like this too: export const initErgo = async (): Promise<Ergo> => {
if (!ergo) {
// Tests are ran using jest (nodejs) otherwise we should be in the browser
ergo = await (process.env.NODE_ENV === 'test'
? import('ergo-lib-wasm-nodejs')
: import('ergo-lib-wasm-browser'));
}
return ergo;
}; |
@ross-weir Anyway, using the node version of the package instead of the browser version for tests is a kind of mocking. Although it works, I really prefer not to mock the whole package in favor of another package. Considering they both get generated from the same rust code, there still may be some differences in the generated code that we lose by mocking. Mocking is a code smell. I think in our case, we can provide the better solution of fixing |
Although it may seem weird to run
ergo-lib-wasm-browser
in Node environments (as we haveergo-lib-wasm-node
), it makes sense when we consider writing tests for apps that useergo-lib-wasm-browser
using tools running in Node. It's not possible to write tests using Jest or Vitest, for example, if we add this package to an app dependencies.The issue is not directly related to
sigma-rust
, however; Unfortunately,wasm-pack
outputpackage.json
only contains amodule
field. There are notype: module
,main
orexports
fields available so that Node can handle the package as expected. There is an open pull request inwasm-pack
repo to fix the issue, but it's not merged yet.Meanwhile, we can wait for
wasm-pack
to fix their issue and use tools such aspatch-package
to bypass the problem, or we can apply some minor modifications to the output ofwasm-pack
and add required fields to the generatedpackage.json
.The text was updated successfully, but these errors were encountered: