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

240
Visualizações
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 Respostas
Responde à pergunta

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 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