I created a new Next.js project using the command: npx create-next-app@latest
The project installs without problems. The created package.json:
{
"name": "test_4",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build --turbopack",
"start": "next start"
},
"dependencies": {
"react": "19.1.0",
"react-dom": "19.1.0",
"next": "15.5.4"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@tailwindcss/postcss": "^4",
"tailwindcss": "^4"
}
}
But when I try to run the test server: npm run build
I get an error:
> [email protected] build
> next build --turbopack
▲ Next.js 15.5.5 (Turbopack)
Creating an optimized production build ...
✓ Finished writing to disk in 24ms
✓ Compiled successfully in 1915ms
✓ Linting and checking validity of types
✓ Collecting page data
[TypeError: Cannot read properties of null (reading 'useContext')]
Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
[TypeError: Cannot read properties of null (reading 'useContext')]
Export encountered an error on /_error: /404, exiting the build.
⨯ Next.js build worker exited with code: 1 and signal: null
I tried running the command without --turbopack: next dev
I tried clearing the npm cache: npm cache clean --force
I tried completely deleting the _npx cache folder
I tried reinstalling the dependencies
I tried to create 404 (not-found.tsx) and 500 (error.tsx) pages
But nothing helped
what could be the problem? why won't my project build?
npm Ibut nothing helped, the error persists