Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  37] [ 2]  / answers: 1 / hits: 13393  / 5 Years ago, mon, september 23, 2019, 12:00:00

I am getting the below error when doing next build in my next.js app, after it's been working fine with just next (or npm run dev).



The error:



$ next build
The module 'react-dom' was not found. Next.js requires that you include it in 'dependencies' of your 'package.json'. To add it, run 'npm install --save react-dom'
Creating an optimized production build ...

> Using external babel configuration
> Location: ../.babelrc
Failed to compile.

./pages/_app.js
Module not found: Can't resolve 'next/head' in '../pages'

> Build error occurred
Error: > Build failed because of webpack errors
at build (.../AppData/Roaming/npm/node_modules/next/dist/build/index.js:7:847)


I started my project by cloning Material UI's next.js example and just use that as it seems updated:



https://github.com/mui-org/material-ui/tree/master/examples/nextjs



However, thinking I just may of have an outdated or broken build, I re-cloned the next.js example and did next build as well, without modifying any files and I get the same error.



How can I fix this?


More From » reactjs

 Answers
11

I just cloned that next.js example and it worked both with npm run dev, as well as npm run build->npm run start.



Judging by your error, I would check that react-dom: latest is present in your package.json's dependencies. Did you run npm install after cloning the example?


[#6163] Friday, September 20, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mattieparisp

Total Points: 612
Total Questions: 109
Total Answers: 104

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
;