node-polyfill-webpack-plugin will check and include the buffer polyfill if any Buffer reference exists. In my setup I separated the polyfills as a different chunk to load dynamiclly if some Web API missing, but in KTX-parse's case it's unintened and hard to work around.
The buffer package is (8kb gziped) and modifies Uint8Array's prototype so better be avoided.
Problem
While
Buffer.from
used in https://github.com/donmccurdy/KTX-Parse/blob/81959373fac956e88f0feaa2bb42dff4bc9542da/src/util.ts#L49-L62 will not be called ifTextEncoder
exists (which is true in in modern environment), it does not work well whennode-polyfill-webpack-plugin
is used in the same application.node-polyfill-webpack-plugin
will check and include thebuffer
polyfill if anyBuffer
reference exists. In my setup I separated the polyfills as a different chunk to load dynamiclly if some Web API missing, but in KTX-parse's case it's unintened and hard to work around.The
buffer
package is (8kb gziped) and modifies Uint8Array's prototype so better be avoided.This behavior affects both
KTX-parse
and the compiled version in Three.js.Possible fixes
As described in https://sindresorhus.com/blog/goodbye-nodejs-buffer avoid the
Buffer
global.TextDecoder
andTextEncoder
are exposed as global in Node.js since v11 (2018) so just delete the check.