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

811
Views
Obtener SyntaxError al usar gráficos ligeros en NextJS

Estoy tratando de usar el paquete lightweight-charts en mi proyecto nextjs , sin embargo, cuando intento llamar a la función createChart , aparece este error en mi consola nodejs.

 ...\lightweight-charts\dist\lightweight-charts.esm.development.js:7 import { bindToDevicePixelRatio } from 'fancy-canvas/coordinate-space'; ^^^^^^ SyntaxError: Cannot use import statement outside a module

Componente:

 import styled from "styled-components" import { createChart } from 'lightweight-charts'; const Wrapper = styled.div`` const CoinPriceChart = () => { const chart = createChart(document.body, { width: 400, height: 300 }); return <Wrapper></Wrapper> } export default CoinPriceChart

Página:

 import styled from "styled-components" import CoinPriceChart from "../../components/charts/CoinPriceChart" const Wrapper = styled.div`` const CoinDetailPage = () => { return ( <Wrapper> <CoinPriceChart /> </Wrapper> ) } export default CoinDetailPage

¿Alguien tiene una idea de lo que podría hacer para permitirme usar la biblioteca dentro de nextjs? ¡Gracias!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Eso porque está intentando importar la biblioteca en contexto SSR. Usar next.js Dynamic con ssr ssr : false debería solucionar el problema:

 import styled from "styled-components" import dynamic from "next/dynamic"; const CoinPriceChart = dynamic(() => import("../../components/charts/CoinPriceChart"), { ssr: false }); const Wrapper = styled.div`` const CoinDetailPage = () => { return ( <Wrapper> <CoinPriceChart /> </Wrapper> ) } export default CoinDetailPage
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!