Closed mstange closed 5 years ago
It looks like loader-utils
getHashDigest
is calling hash.update
with an ArrayBuffer
, which is not expected.
Here's the offending call to getHashDigest
in offline-plugin
:
https://github.com/NekR/offline-plugin/blob/4553b5f5a6a02626b1985db2eb03f1f3622b859a/src/index.js#L480-L497
There doesn't seem to be documentation on the expected types of the buffer
argument to getHashDigest
, but I guess we now know that it accepts the same types as hash.update
, which include TypedArray
and Buffer
but not ArrayBuffer
.
So wrapping the buffer in setHashesMap
should work:
let source = compilation.assets[key].source();
if (source instanceof ArrayBuffer) {
// This is the case for WebAssembly modules.
// getHashDigest doesn't accept ArrayBuffers, so we need to wrap the buffer into something
// that it does support, e.g. a Buffer or a TypedArray.
source = new Uint8Array(source);
}
const hash = loaderUtils.getHashDigest(source, 'sha1');
I have a wip fix for this but had some trouble with the tests... my test was passing even without this fix and I didn't understand why. I can send a PR in a bit.
also experiencing this!
Hey guys. I'll take a look, thank you for reporting this.
Webpack 4 supports modules written in WebAssembly. Here's a commit that adds such a module to the offline-plugin-pwa example:
https://github.com/mstange/offline-plugin-pwa/commit/a4b2fdf232bc2e1711a2c1c8c5639615fe4fe638
However, when using offline-plugin on a project with WebAssembly modules, the offline-plugin build fails:
You can reproduce this by checking out the add-wasm branch in my offline-plugin-pwa fork and running
npm install && npm run build
.