I'm unable to import Tone in my Next.js project. I have Tone as a dependency, but when I run import * as Tone from 'tone'
Next says it can't find the module node_modules/tone/build/esm/core/Global
imported from node_modules/tone/build/esm/index.js
. Originally I thought it was a browser thing, where I had to make sure I was importing Tone only in the browser and not in Node, but dynamically importing (as described here) in the useEffect
hook (which only runs in the browser), but it still couldn't find the module.
The odd thing is that the browser console prints * Tone.js v14.8.38 *
, so clearly Tone exists, but Next can't find it for some reason.
I'm running Next.js version 12, Tone v14.8.38, React 18 and yarn v3.2.0, if that matters. I'd really appreciate any help!
it is currently not possible to run
tone
in node. You should download tone.js from here and include it as a script in your project.you could also try using another library like soundfont