Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Representación de paquete web: "la ventana no está definida"

Uso MERN: https://github.com/Hashnode/mern-starter (react, redux, webpack, nodejs, express) y el componente react-sound: https://github.com/leoasis/react-sound

Cuando incluyo componente

 import Sound from 'react-sound';

e intente iniciar el servidor, tengo el error "window is not defined" de la representación del servidor webpack.

Pero si comento esta línea e inicio el servidor, todo estará bien. Después de eso, puedo descomentar esta línea y el componente funcionará, porque cuando el servidor se está ejecutando, los cambios no activan la representación del servidor (solo la representación frontal).

si lo intento

 if (typeof window !== 'undefined') { const Sound = require('react-sound'); }

y en render

 render() { return ( <div> <Sound playStatus={Sound.status.STOPPED} url="" /> </div> ); }

Tengo ReferenceError: Sound is not defined error en la representación frontal (después del paquete web).

ACTUALIZAR:

Si intento ( var , no const )

 if (typeof window !== 'undefined') { var Sound = require('react-sound'); }

Tengo TypeError: Cannot read property 'status' of undefined en la representación frontal.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Parece que no puedes usar reaccionar-sonido fuera de un entorno de navegador.

La solución puede ser la siguiente:

 let SoundEl; if (typeof window !== 'undefined') { import Sound from 'react-sound'; SoundEl = <Sound playStatus={Sound.status.STOPPED} url="" /> } else { SoundEl = <div></div> }

...

 render() { return ( <div> {SoundEl} </div> ) }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!