Webpack can't import node_modules to Audio Worklets.
See original GitHub issueBug report
Hello, I try to make make an Audio Workets using “aubiojs” library. I installed the library via npm. The worklet works via “WorkerURL” plugin but import of the library breaks it.
My tuner.ts has the following lines:
const frequencyProcessorUrl = new WorkerUrl(new URL('./frequency-processor.ts', import.meta.url));
this.audioContext.audioWorklet.addModule(frequencyProcessorUrl).then(() => {
self.audioWorklet = new AudioWorkletNode(self.audioContext, "frequency-processor");
...
})
frequency-processor.ts:
import aubio from "aubiojs";
aubio();
class FrequencyProcessor extends AudioWorkletProcessor {
...
}
registerProcessor('frequency-processor', FrequencyProcessor);
What is the current behavior?
Webpack replaces aubio()
by webpack_require(/*! aubiojs */ “./node_modules/aubiojs/build/aubio.js”) and can’t resolve this.
If the current behavior is a bug, please provide the steps to reproduce.
Please, look into this branch https://github.com/novikov-alexander/tuner/tree/v-alnovi/pitchTeacher
What is the expected behavior?
I guess that it would be convenient if we could bundle workers code with its dependencies in build time. Currently that’s not possible because it causes an error of undefined AudioWorkletProcessor.
Other relevant information: webpack 5.72
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@alexander-akait
worklet.addModule()
require url as an argument, so right now it is possible only prebuilding worker as scriptUnfortunately your solution still throwing Module not found: Error: Can’t resolve ‘./webworker.min.js’ in ‘J:\Repositories\tuner\app’ on my machine