我尝试在 cpanel 上上传下一个项目,但安装 npm 包时出现错误
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!
安装 npm 软件包时弹出此错误,我已尝试将所有 npm 软件包更新到最新版本,但仍然不起作用,
c面板版本:
Architecture : x86_64
operation system : linux
Perl Version : 5.26.3
Kernel Version: 4.18.0-372.16.1.lve.el8.x86_64
我也尝试过这个 npm 命令,但它也不起作用
npm config set legacy-peer-deps true
server.js 代码是下一个
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 看起来像这样,
{
"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
}
}
架构.prisma :
generator client {
provider = "prisma-client-js"
binaryTargets = ["debian-openssl-3.0.x"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
尝试手动或使用 npm update 更新 npm 软件包,以便所有软件包都会更新到最新版本