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

Trying to use Blake3 in React with TS. Build Warnings and Runtime Errors #43

Open
allidoisace opened this issue Apr 28, 2022 · 2 comments

Comments

@allidoisace
Copy link

Runtime

index.tsx

import('blake3/browser').then(blake3 => {
  console.log(blake3.hash('foo')); // => Uint8Array
});

ReactDOM.render(
  ...
);
[Error] Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'wasm2.memory.buffer')
	getUint8Memory0 (blake3_browser.js:38)
	hash2 (blake3_browser.js:60)
	hash3 (blake3_browser.js:240)
	(anonymous function) (index.tsx:12)
	promiseReactionJob

As posted in an issue elsewhere, they recommended changing the .d.ts names, but they are already present in this version.
rustwasm/wasm-bindgen#2200
Screen Shot 2022-04-28 at 1 13 50 PM

Build Warnings

'memory' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'memory' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_malloc' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_malloc' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'hash' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_free' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'create_hasher' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_malloc' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'create_keyed' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_malloc' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_realloc' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'create_derive' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbg_blake3hash_free' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'blake3hash_reader' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_malloc' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'blake3hash_update' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_malloc' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'blake3hash_digest' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_free' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbg_hashreader_free' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_malloc' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'hashreader_fill' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'__wbindgen_free' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
'hashreader_set_position' is not exported by 'node_modules/blake3/dist/wasm/browser/blake3_js_bg.wasm'
@leonbotros
Copy link

I was able to to fix this by using this webpack config (using craco for example):

module.exports = {
  webpack: {
    configure: (config) => {
      config.experiments = {
        asyncWebAssembly: true,
      };

      config.module.rules.push({
        test: /\.(wasm)$/,
        type: "webassembly/async",
      });

      return config;
    },
  },
};

@allidoisace
Copy link
Author

Will have to see if I can accomplish this with Vite.

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