You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
URL is not defined when adding AudioWorklet in Preact preset #9606
I created a Preact project using yarn create vite and I'm importing my AudioWorklet class as an url using the ?url import syntax. When i try to attach that worklet to my AudioContext i get an Uncaught ReferenceError: URL is not defined in vite's file called client.ts, in this line: const importMetaUrl = new URL(import.meta.url)
This error occurs when i call AudioContext.audioWorklet.addModule(importedWorkletUrl)
Do you know what could be causing this problem or if there's any way to successfully use worklets in this setup?
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
This is because Vite injects HMR code for Processor.ts when being imported, which imports from Vite's client.ts, which isn't compatible in an AudioWorklet environment. Since Worklets are an experimental feature, and they should ideally support common globals like URL, I think this is something we won't support for the time being.
For now you can workaround it by placing the processor JS code inside the public directory, and import the module from there.
Activity
bluwy commentedon Aug 16, 2022
This is because Vite injects HMR code for
Processor.tswhen being imported, which imports from Vite'sclient.ts, which isn't compatible in an AudioWorklet environment. Since Worklets are an experimental feature, and they should ideally support common globals likeURL, I think this is something we won't support for the time being.For now you can workaround it by placing the processor JS code inside the public directory, and import the module from there.
pyotrr commentedon Aug 16, 2022
Understandable, thanks!