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

238
Views
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 answers
Answer question

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