Troubleshooting
Encountering issues with the project? This guide covers some common problems and their solutions.
Installation Issues
Error: Cannot find module 'next'
This error usually occurs when Next.js is not properly installed. Try the following:
- Delete the
node_modulesfolder andpackage-lock.jsonfile. - Run
npm installoryarn installagain. - If the issue persists, try installing Next.js explicitly:
npm install next react react-dom
Build Errors
Error: Image Optimization using Next.js' default loader is not compatible with next export.
If you're using next export, you need to use a different image loader. Modify your next.config.js:
module.exports = {
images: {
loader: 'custom',
loaderFile: './my-loader.js',
},
}Then create a my-loader.js file in your project root:
export default function myLoader({ src }) {
return src
}Runtime Errors
ReferenceError: window is not defined
This error occurs when trying to access the window object on the server side. Wrap your code in a check:
if (typeof window !== 'undefined') {
// Your code here
}Performance Issues
Slow Page Loads
- Ensure you're using production builds (
next buildandnext start). - Implement code splitting and lazy loading for large components.
- Optimize images and use Next.js Image component.
- Minimize CSS and JavaScript files.
If you encounter any issues not covered here, please check our GitHub issues or reach out to our support team.