Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
How to load theme javascript files in nextjs

I am going to use a theme of themeforest on Next.js

I tried to load jquery core and some plugins, but Nextjs can't load it.

import { useEffect } from "react"
import { SessionProvider } from "next-auth/react"
import Script from 'next/script'

import '../public/plugin/datatables/responsive.dataTables.min.css'
import '../public/plugin/datatables/dataTables.bootstrap5.min.css'

import '../public/css/cryptoon.style.min.css'
// import "./styles.css"

export default function App({ Component, pageProps }) {
  return (
    
    <div>
    <SessionProvider session={pageProps.session}>
      <Component {...pageProps} />
    </SessionProvider>
    
    <Script type="text/javascript" src="/bundles/libscripts.bundle.js" strategy="lazyOnload" />
    <Script type="text/javascript" src="/bundles/apexcharts.bundle.js" strategy="lazyOnload" />
    <Script type="text/javascript" src="/js/template.js" strategy="lazyOnload" />
    <Script type="text/javascript" src="/js/page/index.js" strategy="lazyOnload" /> 
    </div>
  )
}

But a bunch of errors have occurred:

Unhandled Runtime Error
TypeError: Cannot read properties of null (reading 'addEventListener')

Call Stack
HTMLDocument.<anonymous>
/js/template.js (185:18)
e
/bundles/libscripts.bundle.js (1:29754)
t
/bundles/libscripts.bundle.js (1:30078)

....

How to load template(HTML/CSS/JAVASCRIPT) to Nextjs component?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I would recommend you to use next/head I normally use this to put my scripts but it depends on your case, remember that using different strategies (like lazyOnload) and the order in some cases is important, but if you require to use next/script as the docs says then, check your strategies try with other ones like beforeInteractive and double check the order in which your scripts should be loaded and if you continue getting those errors probably the error is related with the content of your scripts, open your network tab and inspect what happened.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda