question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack can't import node_modules to Audio Worklets.

See original GitHub issue

Bug 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:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vankopcommented, May 12, 2022

@alexander-akait worklet.addModule() require url as an argument, so right now it is possible only prebuilding worker as script

0reactions
novikov-alexandercommented, May 13, 2022

Unfortunately your solution still throwing Module not found: Error: Can’t resolve ‘./webworker.min.js’ in ‘J:\Repositories\tuner\app’ on my machine

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make AudioWorklets work with vue-cli/webpack/babel ...
js import worklet from 'worklet-loader!./processor.js' class MyWorkletNode extends AudioWorkletNode { constructor(context) { super(context ...
Read more >
How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial on transpilation in Node.js.
Read more >
Implementing AudioWorklets with React - HackerNoon
I was fiddling around and discovered that the addModule('path/to/your/module') method points there by default. No imports, no requires, no { ...
Read more >
Enter Audio Worklet - Chrome Developers
To enable custom audio processing in JavaScript, the Web Audio API proposed a ScriptProcessorNode which used event handlers to invoke user ...
Read more >
Deployment - The `wasm-bindgen` Guide
bundler, Suitable for loading in bundlers like Webpack. web, Directly loadable in a web browser. nodejs, Loadable via require as a Node.js module....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found