* Tone.js v14.8.39 * Tone.min.js:8:132717 Error: Tone.js loaded but window.Tone undefined
- User
- Tone.js v14.8.39 * Tone.min.js:8:132717 Error: Tone.js loaded but window.Tone undefined
- Assistant
The error message:
Tone.js loaded but window.Tone undefined
indicates that although the Tone.js script file was fetched and presumably executed, the global window.Tone object was not properly created. This is unusual because Tone.js normally attaches itself to window.Tone when loaded in a browser environment.
Here are several common reasons and troubleshooting steps for this problem:
Make sure you are including the Tone.js script correctly in your HTML:
<script src="path/to/Tone.min.js"></script>
<script>
console.log(window.Tone); // Should not be undefined
</script>
Tone.min.js file should be valid and accessible.type="module" attribute if you want global Tone.defer or async if you attempt to access window.Tone immediately after the script tag.Tone.js v14+ supports ES modules. If you try loading the UMD build directly but also use module scripts or bundlers improperly, it can cause conflicts or fail to assign to window.Tone.
<script type="module">, Tone.js may not attach to window by default.import * as Tone from "https://cdn.skypack.dev/tone";
console.log(Tone);
In this scenario, window.Tone may be undefined because the module is scoped, not attached globally.
If your page or build system includes Tone.js multiple times or as part of a complex bundle, the global window.Tone may get overwritten or not correctly assigned.
Open your browser console and run:
console.log(window.Tone);
undefined, the script likely did not attach globally.Try loading Tone.js from the official CDN and see if the problem persists:
<script src="https://cdn.jsdelivr.net/npm/tone@14.8.39/build/Tone.min.js"></script>
<script>
console.log('Tone:', window.Tone);
</script>
If this works, the problem is likely your local script or setup.
type="module"), import Tone explicitly; don’t rely on global window.Tone.If you provide your HTML or JavaScript setup, I can help debug the exact cause.