uint8array-loader

raw JSON →
1.0.2 verified Sat Apr 25 auth: no javascript

Webpack loader that returns file content as a Uint8Array, useful for loading binary files (e.g., FlatBuffers schemas) in webpack bundles. Current stable version is 1.0.2, with no recent releases. It is designed to be used with babel-loader, but actually works as a standalone loader. Unlike raw-loader or file-loader, this loader returns an actual Uint8Array object instead of a string or URL. The package has minimal dependencies and is intended for webpack projects needing binary data in array buffer form.

error Module not found: Error: Can't resolve 'uint8array-loader'
cause The loader package is not installed or listed in devDependencies.
fix
Run 'npm install --save-dev uint8array-loader' to install it.
error TypeError: (intermediate value).call is not a function
cause The loader is being used without webpack, or the loader version is incompatible with the webpack version.
fix
Ensure you are using webpack 4 and that the loader is applied as a rule, not as a plugin.
error Cannot read property 'getOptions' of undefined
cause Webpack 5 removed loader options via this.getOptions; this loader expects an older webpack API.
fix
Use webpack 4 or switch to asset modules for binary files.
gotcha The package name is misspelled 'unit8array' but the export returns 'Uint8Array' correctly.
fix Import the loader as 'uint8array-loader' (note the typo).
gotcha This loader does not work with webpack 5 out of the box if babel-loader is not installed, as it lists babel as a dependency but actually not required.
fix Ensure webpack is installed; remove babel-loader if not used.
breaking Loader returns Uint8Array, which may not be expected if you are used to raw-loader returning a string.
fix If you need a string, convert using TextDecoder or use raw-loader instead.
deprecated The package has not been updated since 2018 and may have compatibility issues with modern webpack versions.
fix Consider using asset modules in webpack 5 to load binary data.
gotcha The loader's repository URL in npm points to a 404 page; it is unmaintained.
fix Fork the package or use an alternative loader.
npm install uint8array-loader
yarn add uint8array-loader
pnpm add uint8array-loader

Shows how to configure webpack to use uint8array-loader for .bfbs files and import the binary content as a Uint8Array.

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.bfbs$/,
        use: 'uint8array-loader'
      }
    ]
  }
};

// app.js
import binaryData from './schema.bfbs';
console.log(binaryData instanceof Uint8Array); // true
console.log(binaryData.byteLength);