Vercel构建报错:react-redux与react-hot-toast模块未找到求助
Vercel部署Next.js项目模块解析失败问题求助
在Vercel部署Next.js项目时,构建过程提示无法解析react-redux和react-hot-toast模块。已安装这两个依赖的最新版本,且设置了git config core.ignorecase false,但问题仍未解决,寻求帮助。
报错信息
[09:18:19.997] 153 packages are looking for funding [09:18:19.997] run `npm fund` for details [09:18:20.020] Detected Next.js version: 15.0.2 [09:18:20.024] Running "npm run build" [09:18:20.555] [09:18:20.557] > client@0.1.0 build [09:18:20.560] > next build [09:18:20.562] [09:18:21.278] Attention: Next.js now collects completely anonymous telemetry regarding usage. [09:18:21.278] This information is used to shape Next.js' roadmap and prioritize features. [09:18:21.278] You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL: [09:18:21.279] https://nextjs.org/telemetry [09:18:21.279] [09:18:21.339] ▲ Next.js 15.0.2 [09:18:21.340] - Environments: .env [09:18:21.340] [09:18:21.418] Creating an optimized production build ... [09:18:52.597] Failed to compile. [09:18:52.598] [09:18:52.598] ./app/Provider.tsx [09:18:52.598] Module not found: Can't resolve 'react-redux' [09:18:52.598] [09:18:52.598] https://nextjs.org/docs/messages/module-not-found [09:18:52.598] [09:18:52.598] Import trace for requested module: [09:18:52.598] ./app/layout.tsx [09:18:52.599] [09:18:52.599] ./app/components/Admin/Course/AllCourses.tsx [09:18:52.599] Module not found: Can't resolve 'react-hot-toast' [09:18:52.599] [09:18:52.599] https://nextjs.org/docs/messages/module-not-found [09:18:52.599] [09:18:52.599] ./app/components/Admin/Course/CourseContent.tsx [09:18:52.599] Module not found: Can't resolve 'react-hot-toast' [09:18:52.599] [09:18:52.599] https://nextjs.org/docs/messages/module-not-found [09:18:52.599] [09:18:52.599] Import trace for requested module: [09:18:52.600] ./app/components/Admin/Course/EditCourse.tsx [09:18:52.600] ./app/admin/edit-course/[id]/page.tsx [09:18:52.600] [09:18:52.600] ./app/components/Admin/Course/CourseData.tsx [09:18:52.600] Module not found: Can't resolve 'react-hot-toast' [09:18:52.600] [09:18:52.600] https://nextjs.org/docs/messages/module-not-found [09:18:52.600] [09:18:52.600] Import trace for requested module: [09:18:52.600] ./app/components/Admin/Course/EditCourse.tsx [09:18:52.600] ./app/admin/edit-course/[id]/page.tsx [09:18:52.600] [09:18:52.600] ./app/components/Admin/Course/CreateCourse.tsx [09:18:52.600] Module not found: Can't resolve 'react-hot-toast' [09:18:52.601] [09:18:52.601] https://nextjs.org/docs/messages/module-not-found [09:18:52.601] [09:18:52.601] Import trace for requested module: [09:18:52.601] ./app/admin/create-course/page.tsx [09:18:52.601] [09:18:52.616] [09:18:52.616] > Build failed because of webpack errors [09:18:52.644] Error: Command "npm run build" exited with 1 [09:18:53.011]
package.json内容
{ "name": "client", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "@mui/icons-material": "^6.1.6", "@mui/x-data-grid": "^7.22.2", "@stripe/react-stripe-js": "^2.8.1", "@stripe/stripe-js": "^4.9.0", "axios": "^1.7.7", "next": "^15.0.2", "next-auth": "^4.24.10", "next-themes": "^0.4.3", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hot-toast": "^2.4.1", "react-icons": "^5.3.0", "react-pro-sidebar": "^0.7.1", "react-redux": "^9.1.2", "recharts": "^2.13.3", "socket.io-client": "^4.8.1", "stripe": "^17.3.1", "timeago.js": "^4.0.2" }, "devDependencies": { "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "eslint": "^8", "eslint-config-next": "15.0.2", "postcss": "^8", "tailwindcss": "^3.4.1", "typescript": "^5" } }
Provider.tsx代码
import React from "react" import { Provider } from "react-redux" import { store } from "../redux/store" interface ProviderProps { children: any; } export function Providers({ children }: ProviderProps) { return <Provider store={store}>{children}</Provider> }
已执行操作
- 安装了
react-redux和react-hot-toast的最新版本 - 设置了
git config core.ignorecase false
解决方案尝试
确认锁文件已提交
检查package-lock.json是否已添加到Git仓库并提交。Vercel依赖锁文件安装依赖,缺失会导致版本不匹配或安装失败。本地重新安装依赖
执行以下命令清除缓存并重新安装,之后提交代码:rm -rf node_modules package-lock.json npm install强制Vercel重新安装依赖
在Vercel项目设置的"Build & Development Settings"中,将"Install Command"改为npm install --force,避免缓存导致的依赖问题。检查导入路径大小写
确认代码中导入语句的包名大小写完全正确,比如必须是import { Provider } from 'react-redux',不能写成React-Redux这类变体。验证版本兼容性
Next.js 15.0.2属于较新版本,可临时降级到14.x稳定版,测试是否因版本兼容问题导致模块无法解析。清除Vercel构建缓存
在Vercel控制台选择项目的"Redeploy",并勾选"Clear build cache"选项,清除旧缓存后重新部署。
内容的提问来源于stack exchange,提问作者Faiz suhaimi
相关产品推荐
相关产品推荐

