0

Error: Several Installation fails upon Next.js installation including a package loss revealed during build

peema@DESKTOP-6UGCO8V MINGW64 ~/Documents/alert/peeapp $ next build The module 'react' was not found. Next.js requires that you include it in 'depen dencies' of your 'package.json'. To add it, run 'npm install react' The module 'react-dom' was not found. Next.js requires that you include it in 'd ependencies' of your 'package.json'. To add it, run 'npm install react-dom' uncaughtException Error: Cannot find module '@next/env'

Bonsu
  • 67
  • 1
  • 5

1 Answers1

0

Diagnosing Next.js installation process and failure and next build failure. An installation process that worked in a breakdown

PRECHECK a)Open permissions to avoid permission restriction and fail b)If permission is an issue, set permission to Everybody, User etc. on your Windows or Mac c) Check anti-virus issues(antivirus can block files)

INSTALLATION

  1. yarn global add create-next-app- (to make it accessible and to create binary )
  2. npm install -g npm@latest - (to make it ready for npm files _
  3. yarn create next-app peeapp - (create project )
  4. yarn global bin -(to check binary - check binary path)
  5. yarn global list - (check if the project exists in global list)
  6. create-next-app peeapp - (this is what creates the project)

PATH FIXES

  1. If you have path error, put the path of the project and the bin directory in the System Environment Variables both as a Users & System
  2. Check for the binary. Eg C:\Users\peema.yarn-global\bin, and you can place it in Path at the System or User Environment Variables

PROBLEM: NEXT BUILD REACT ERROR AND INSTALLATION ERRORS FOR NEXT BUILD **However, there is an issue, next.js installs the project in the directory where you run the create-next-app command (rightly so). but a problem with 'next build' occurs

Let's take the two path a) C:\Users\peema\Documents\alert\peeapp\node_modules b) C:\Users\peema\node_modules*

The project was installed in peeapp folder hence the node_modules (C:\Users\peema\Documents\alert\peeapp\node_modules) but (next build ) calls the second path (C:\Users\peema\node_modules )

So packages like react, next, and others cannot be found since they are not in the second path but were installed in the first.

SOLUTION: Copy all packages that are not in the first node_modules to the second so that those packages can be found.

Bonsu
  • 67
  • 1
  • 5