First time using NextJS, why is this not working. When clicking the button there is no log message in the browser. I have also tried adding onChange to an <input />
however again, doesn’t fire.
I have removed all styling from the globals.css and page.module.css file – this is literally a completely fresh NextJS project using npx create-next-app@latest
"use client";
export default function Home() {
function handleClick() {
console.log("hello");
}
return (
<main>
<button type="button" onClick={handleClick}>
Click
</button>
</main>
);
}
2
Answers
This was caused due to my Node.js being on v16.13.1. Updating to the latest version (currently v18.17.1) and also running
npm update npm -g
fixed the problem.There seems to be nothing wrong with the code. Please try to quit your node server and start again