Next.js Discord

Discord Forum

Console Command Not Working In Export Mode

Unanswered
Mugger Crocodile posted this in #help-forum
Open in Discord
Mugger CrocodileOP
Hi, so in regular nextjs (npm run dev) i can through the javascript console run window.GameHUD.toggleVoice() for example and it works normally. however after running npm run build in "export mode" it doesn't work. (note that i run the html file right away and the function can't be executed from the console.) next config:
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export'
}

export default nextConfig
Thank you

3 Replies

@joulev How did you add/declare window.GameHUD in your app?
Mugger CrocodileOP
Hey, i'm doing "useImperativeHandle" to declare multiple functions and then expose the ref on the global window object.
useEffect(() => {
    if (ref && typeof window !== "undefined") {
      ;(window as any).huds = ref.current
    }
  }, [ref])
Thanks.
Mugger CrocodileOP
I solved this issue by switching to vite.