Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
Cannot import Tone.js is in a Next.js project

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!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You are on the right track with the dynamic loading, I've got a large project doing it that way. This is how I've done it (although I can't really see what you have done wrong) -

const DynamicComponent = dynamic(
  () => import('../components/foobar'),
  { ssr: false }
)

More details can be seen here (although I see you posted that already). https://nextjs.org/docs/advanced-features/dynamic-import

Inside your component you can import tone objects in the following fashion eg.

import { Clock, Merge, Oscillator, Player, Waveform } from "tone";

I have used useEffect to instantiate tone classes, but I have also done it using JS classes. Both ways worked for me.

Is this different from what you did? Just to check you are doing the dynamic import at the page level right? And how are you importing the tone objects? This depends on your specific code.

I'm using

"next": "^10.0.9",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"tone": "^14.7.77"

Might be worth downgrading to these and trying.

about 4 years ago · Juan Pablo Isaza Relatório

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda