I used the commands for my nextjs project on my terminal and got the issue solved.
rm -rf ./next ./node_modules ./package-lock.json after that yarn && yarn dev
rm -rf ./next ./node_modules ./package-lock.json
yarn && yarn dev