1

I'm struggling to simply get Tone.js to work at all. At first I realized I needed to activate the web audio context on a button click. However, now I'm running into this issue: Tone.start is not a function.

My code is the simplest, shortest possible I could get it:

index.html:

<!DOCTYPE html>
<html>
    <head>
        <title>Tone.js</title>
        <meta charset="utf-8" />

        <script type="module" src="app.js"></script>
    </head>
    <body>
        <button>Start</button>
    </body>
</html>

App.js:


import * as Tone from './node_modules/tone/build/Tone.js'

window.onload = function() {

    document.getElementsByTagName('button')[0].addEventListener('click', startTone);
}

async function startTone() {
    await Tone.start();

}

This is based on the official documentation, under "Starting Audio". Also for reference I'm running this in Chrome.

Vee
  • 729
  • 10
  • 27
  • It might not be getting imported correctly. Check your network tab, correlate it with your file system, and also do `console.log(Tone)` to see what it is – CertainPerformance Feb 13 '22 at 20:34
  • No issues in the network tab... I console logged it at the top of window.onload and it shows: Module {Symbol(Symbol.toStringTag): 'Module'} Symbol(Symbol.toStringTag): "Module" – Vee Feb 13 '22 at 20:44
  • I assume you're not using any build here, just serving up the HTML and module directly? If so, try `import './node_modules/tone/build/Tone.js'`, or switch to a build and use the recommended `import * as Tone from 'tone'`. – ggorlen May 30 '22 at 03:02

0 Answers0