I am trying to build my nextjs project but its failing every time. Project works without a single error in development but fails in build.
Tried deleting node_modules
and reinstalling packages but no luck.
After long searching I finally found duplicate of this, but it has been removed by its author.
Build log
> next build
info - Loaded env from /home/user/Documents/projects/webdev/myproject/.env.local
info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
info - Checking validity of types
info - Creating an optimized production build .../home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:59190
processContextHashSnapshot(path, tsh.hash);
^
TypeError: Cannot read property 'hash' of null
at callback (/home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:59190:46)
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:57683:39
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:135587:5
at Hook.eval [as callAsync] (eval at create (/home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:33832:10), <anonymous>:4:1)
at AsyncQueue._handleResult (/home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:135557:21)
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:135540:11
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:59794:14
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:59452:6
at done (/home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/neo-async/async.js:1:10308)
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:59736:9
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:135587:5
at Hook.eval [as callAsync] (eval at create (/home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:33832:10), <anonymous>:4:1)
at AsyncQueue._handleResult (/home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:135557:21)
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:135540:11
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:59794:14
at /home/user/Documents/projects/webdev/myproject/node_modules/next/dist/compiled/webpack/bundle5.js:59452:6
CodePudding user response:
Fixed it by clearing the vercel build cache by using the --force
flag during deployment.
CodePudding user response:
Deleting .next/
dir solved my problem.