You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js项目本地与Vercel构建失败排查求助

Next.js 本地与Vercel构建失败排查求助

我正在搭建首个Next.js网站,此前曾成功完成本地构建,但目前本地和Vercel平台均出现构建失败问题。

package.json 配置

{
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "@chakra-ui/icons": "^2.0.17",
    "@chakra-ui/react": "^2.5.1",
    "@emotion/react": "^11.10.6",
    "@emotion/styled": "^11.10.6",
    "@fontsource/dm-sans": "^4.5.9",
    "@tanstack/react-table": "^8.7.9",
    "@types/react-table": "^7.7.14",
    "framer-motion": "^9.0.4",
    "mongodb": "^4.8.1",
    "next": "latest",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-icons": "^4.8.0",
    "react-query": "^3.39.3"
  },
  "devDependencies": {
    "@types/node": "18.7.5",
    "@types/react": "16.9.17",
    "typescript": "4.6.3"
  }
}

构建错误信息

执行npm run build时出现如下错误:

  • 本地和Vercel均出现的错误:
info  - Linting and checking validity of types .Failed to compile.

./node_modules/framer-motion/dist/index.d.ts:1212:28
Type error: ';' expected.

  1210 | declare type HydratedFeatureDefinition = {
  1211 |     isEnabled: (props: MotionProps) => boolean;
> 1212 |     Feature: typeof Feature<unknown>;
       |                            ^
  1213 |     ProjectionNode?: any;
  1214 |     MeasureLayout?: typeof MeasureLayout;
  1215 | };
  • 仅Vercel出现的错误:
Failed to compile.
./node_modules/framer-motion/dist/index.d.ts:1212:28
Type error: ';' expected.

tsconfig.json 配置

{
    "compilerOptions": {
        "target": "es5",
        "lib": ["dom", "dom.iterable", "esnext"],
        "allowJs": true,
        "skipLibCheck": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "noEmit": true,
        "incremental": true,
        "esModuleInterop": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "jsx": "preserve"
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
    "exclude": ["node_modules"]
}

补充说明

我并未直接使用framer-motion,它是ChakraUI的依赖包。构建完成后,VS Code还会出现找不到部分导入的异常错误:
VS Code TypeScript错误截图

已尝试的解决方法

  • 删除node_modules和package-lock.json,重新执行npm i
  • 卸载framer-motion
  • 在Vercel中将Node版本从18切换为16和14(均无效)

实在不知道该从何处着手,希望有人能提供解决思路。谢谢


内容的提问来源于stack exchange,提问作者Pοlatic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 18:28:11