Registry / audio-worklet-loader

audio-worklet-loader

JSON →
library1.1.0jsnpmunverified

Webpack loader for Audio Worklet processors, enabling bundling and module resolution for .worklet.js and .worklet.ts files. Version 1.1.0 is stable but explicitly does not support Webpack 4. It can inline worklet code as a Blob to avoid separate chunks, with fallback modes for bundling. This loader fills a niche for web audio applications needing AudioWorklet support in Webpack 5, similar to worker-loader but for audio worklets.

npm install audio-worklet-loader
INSTALL
IMPORT
SIG · AUDIO-WORKLET-LOAD
A
audio-worklet-loader
javascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (import from worklet file)
import workletURL from 'audio-worklet-loader!./processor.worklet.js';
import workletURL from './processor.worklet.js';
The loader must be applied via inline syntax or webpack config rule; otherwise the import returns the raw module, not the worklet URL.
webpack rule for .worklet.js
module.exports = { module: { rules: [ { test: /\.worklet\.js$/, loader: 'audio-worklet-loader' } ] } };
module.exports = { module: { rules: [ { test: /\.worklet\.js$/, use: 'audio-worklet-loader' } ] } };
Use 'loader' not 'use' in rule; 'use' is for multiple loaders and may cause unexpected behavior. Also ensure loader is applied before ts-loader for .worklet.ts files.
options inline
loader: 'audio-worklet-loader', options: { inline: 'no-fallback' }
options: { inline: true }
The inline option accepts string 'fallback' or 'no-fallback', not boolean. Missing or invalid value defaults to undefined (no inlining).

Minimal Webpack config using audio-worklet-loader with inline option, and an async function that loads an AudioWorklet from the bundled URL.

// webpack.config.js const path = require('path'); module.exports = { entry: './index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', }, module: { rules: [ { test: /\.worklet\.js$/i, loader: 'audio-worklet-loader', options: { inline: 'no-fallback' }, }, ], }, target: 'web', mode: 'development', }; // index.js async function main() { const audioCtx = new AudioContext(); const workletUrl = require('audio-worklet-loader!./random-noise.worklet.js'); await audioCtx.audioWorklet.addModule(workletUrl); const node = new AudioWorkletNode(audioCtx, 'random-noise'); node.connect(audioCtx.destination); } main();
Debug
Known issues
breakingWebpack 4 is not supported. Do not attempt to use this loader with Webpack 4; it will fail.
fix
Use Webpack 5 (>=5.0.0) exclusively.
affects: 1.0.0 - 1.1.0
gotchaThe loader must appear before ts-loader in the rules array when processing .worklet.ts files, otherwise TypeScript compilation will break.
fix
Order rules so audio-worklet-loader is first for .worklet.ts files, then ts-loader for other .ts files.
affects: >=1.0.0
gotchaInline option values are case-sensitive strings: 'fallback' or 'no-fallback'. Using boolean true or misspelling will cause the option to be ignored (no inlining).
fix
Pass { inline: 'no-fallback' } in options object.
affects: >=1.0.0
deprecatedThe require() usage in older examples is not technically deprecated but ESM imports are preferred. The loader works with both import and require.
fix
Use import workletURL from 'audio-worklet-loader!./file.worklet.js'; for modern ES modules.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Module parse failed: Unexpected token (1:0) in ... The loader may need to be configured.
The rule for .worklet.js files is not correctly defined or the loader is not applied.
fix
Ensure webpack config has a rule: { test: /\.worklet\.js$/, loader: 'audio-worklet-loader' }
TypeError: Cannot read properties of undefined (reading 'addModule') - workletUrl is undefined
The inline import returned undefined because inline option 'no-fallback' was used but the file wasn't actually inlined (maybe misconfiguration).
fix
Check that the rule matches the file extension and the loader is applied. Use 'fallback' mode or omit inline to always get a URL.
Uncaught DOMException: Failed to execute 'addModule' on 'AudioWorklet': '...url...' is not a valid URL.
The worklet URL returned by the loader is not a proper blob or file URL; likely the loader didn't process the file.
fix
Verify the loader is applied in webpack config and the import path includes the loader prefix: 'audio-worklet-loader!./file.worklet.js'
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
webpackrequiredPeer dependency required; loader only works with Webpack 5, Webpack 4 not supported.
Agent activity
4 hits · last 30 days
node
4
Resources
audio-worklet-loader — npm install audio-worklet-loader · libregistry