Module parse failed: magic header not detected (error loading wasm)
See original GitHub issueEnvironment
Node v16.13.0
@callstack/repack 2.5.2
More details in reproducible demo
Description
Error in "./node_modules/bsv-wasm-bundler/bsv_wasm_bg.wasm": Module parse failed: magic header not detected
File was processed with these loaders:
* ./node_modules/@callstack/repack/assets-loader.js
You may need an additional loader to handle the result of these loaders.
Error: magic header not detected
Is this expected behaviour? Is the header
necessary if this asset (the wasm file) doesn’t need sent over the network since it will be bundled with the app? Any suggestions on how to resolve this?
Reproducible Demo
The result of the following steps can be found here https://github.com/1guzzy/AwesomeProject
npx react-native init AwesomeProject --version 0.68.3
- setup repack using https://re-pack.netlify.app/docs/getting-started
- https://github.com/callstack/repack/blob/main/templates/webpack.config.js#L184-L186 ->
test: ReactNative.getAssetExtensionsRegExp([...ReactNative.ASSET_EXTENSIONS, 'wasm']),
- also add the following to the config
experiments: {
asyncWebAssembly: true
},
- install wasm library
npm install bsv-wasm-bundler --save
- import library
import { PrivateKey } from 'bsv-wasm-bundler'
& useconst random = PrivateKey.fromRandom().toHex()
- Note: if you get this error
Error in "./App.js": Module not found: Error: Can't resolve 'bsv-wasm-bundler'
you have to add"main": "bsv_wasm",
tonode_modules/bsv-wasm-bundler/package.json
Issue Analytics
- State:
- Created a year ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
WASM react module parse failed: magic header not detected
I was getting the magic number error when fetching the wasm from its javascript wrapper (e.g. a.out.js) because of a routing problem with...
Read more >Wasm React Module Parse Failed: Magic Header ... - ADocLib
magic header not detected File was processed with these loaders:. I have issue using webassembly wasm file in React with Typescript. const path...
Read more >wasm-loader | Yarn - Package Manager
A simple .wasm binary file loader for Webpack. Import your wasm modules directly into your bundle as Constructors which return WebAssembly.Instance .
Read more >[Solved]-React - Module parse failed-Reactjs
[Solved]-React - Module parse failed-Reactjs · npm i --save-dev babel-loader babel-preset-react babel-preset-es2015 · add to webpack.config.js configs for babel- ...
Read more >Check-in [67f13ff3ae] - SQLite
Use a wasm runtime error, because a JS error might be seen as a foreign ... if (!response['ok']) { throw "failed to load...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Don’t bother with non async Wasm loading. Pretty sure V8 at least has a cap on the size of the binary it’ll load synchronously and it’s small enough to not matter for anything useful since it forces the runtime to freeze the main thread while loading the binary.
Okay gotcha, I’m out of my depth with ReactNative as I’ve never used it in the past.
Anytime you get a header error it’s a sure sign that the runtime is not getting a correct binary format. So I’d look into why that is. Loaders can be weird and may change the contents of the original file to make it “work” within a webpack app. What you’re looking for is for the raw binary Buffer containing the contents of the original file being passed to the JS runtime.