skip to Main Content

i’ve trying to upload next project on a cpanel but in there is a error while installing npm packages

npm ERR! code ERESOLVEnpm ERR! ERESOLVE unable to resolve dependency treenpm ERR!
ERR! Found: [email protected] ERR! node_modules/nextnpm ERR!   
next@"^13.4.15" from the root projectnpm ERR! npm ERR! 
Could not resolve dependency:npm ERR! peer next@"2 - 5" 
from [email protected] ERR! node_modules/next-routernpm ERR!   
next-router@"^1.3.6" 
from the root projectnpm ERR! npm ERR! 
Fix the upstream dependency conflict, or retrynpm ERR! this command with --force, or --legacy-peer-depsnpm ERR!

this error pops up when installing npm packages, i’ve tried everything updating all the npm packages to the latest versions and it still does not works,

cpanel version :

Architecture : x86_64
operation system : linux
Perl Version : 5.26.3
Kernel Version: 4.18.0-372.16.1.lve.el8.x86_64

ive tried this npm command too but it does not worked also

npm config set legacy-peer-deps true

server.js code is next

const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')
 
const dev = process.env.NODE_ENV !== 'production'
const hostname = process.env.NODE_ENV !== "production" ? "localhost" : "website.com"


const port = process.env.PORT || 4790
// process.env.PORT || 4789

// when using middleware hostname and port must be provided below
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()
 
app.prepare().then(() => {
  createServer(async (req, res) => {
    try {
      // Be sure to pass true as the second argument to url.parse.
      // This tells it to parse the query portion of the URL.
      const parsedUrl = parse(req.url, true)
      const { pathname, query } = parsedUrl
 
      if (pathname === '/a') {
        await app.render(req, res, '/a', query)
      } else if (pathname === '/b') {
        await app.render(req, res, '/b', query)
      } else {
        await handle(req, res, parsedUrl)
      }
    } catch (err) {
      console.error('Error occurred handling', req.url, err)
      res.statusCode = 500
      res.end('internal server error')
    }
  })
    .once('error', (err) => {
      console.error(err)
      process.exit(1)
    })
    .listen(port, () => {
      console.log(`> Ready on http://${hostname}:${port}`)
    })
})

package json looks like this,

{
  "name": "mywebsite",
  "version": "0.1.0",
  "private": true,
  "homepage": "https://website.ge",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "NODE_ENV=production node server.js",
    "lint": "next lint"
  },
  "dependencies": {
    "@headlessui/react": "^1.7.16",
    "@next-auth/prisma-adapter": "^1.0.7",
    "@prisma/client": "^5.1.1",
    "@semcore/ui": "^15.24.0",
    "@studio-freight/lenis": "^1.0.19",
    "@types/node": "20.4.9",
    "@types/react": "18.2.20",
    "@types/react-dom": "18.2.7",
    "autoprefixer": "10.4.14",
    "axios": "^1.5.0",
    "bcrypt": "^5.1.0",
    "eslint": "8.46.0",
    "eslint-config-next": "13.4.13",
    "framer-motion": "^10.15.2",
    "i": "^0.3.7",
    "i18next": "^23.4.4",
    "next": "^13.4.15",
    "next-auth": "^4.22.5",
    "next-intl": "^3.0.0-beta.10",
    "next-navigation": "^1.0.6",
    "next-router": "^1.3.6",
    "npm": "^9.8.1",
    "popper.js": "^1.16.1",
    "postcss": "8.4.27",
    "prisma": "^5.1.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-hook-form": "^7.45.4",
    "react-hot-toast": "^2.4.1",
    "react-icons": "^4.10.1",
    "react-phone-number-input": "^3.3.6",
    "react-spinners": "^0.13.8",
    "swiper": "^10.1.0",
    "tailwindcss": "3.3.3",
    "typescript": "5.1.6",
    "usehooks-ts": "^2.9.1",
    "zustand": "^4.4.1"
  },
  "devDependencies": {
    "@types/bcrypt": "^5.0.0",
    "@types/leaflet": "^1.9.3",
    "@types/react-date-range": "^1.4.4",
    "autoprefixer": "^10.4.14",
    "postcss": "^8.4.21",
    "prisma": "^4.11.0",
    "tailwindcss": "^3.2.7"
  },
  "browser": {
    "fs": false,
    "path": false,
    "os": false
  }
}

schema.prisma :

generator client {
  provider = "prisma-client-js"
  binaryTargets = ["debian-openssl-3.0.x"]
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

2

Answers


  1. try to update npm packages manually or with npm update so all the packages will be updated to the latest version

    Login or Signup to reply.
  2. You can install by adding this flag at the of command

      npm install --legacy-peer-deps
    
    # or use the --force flag
    npm install --force
    

    or set it globally

    npm config set legacy-peer-deps true
    

    or the last alternative

    delete node modules

    rm -rf node_modules
    rm -f package-lock.json
    

    clean the cache

    npm cache clean --force
    

    run the above install command

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search