Vercel、Next.js、Sanity.io生产部署失败

i2byvkas  于 2023-01-02  发布在  其他
关注(0)|答案(1)|浏览(170)

我有一个Next.js + Sanity.io项目,当我使用vercel CLI从本地构建进行部署时,
vercel build然后vercel deploy --prebuilt,它工作得很好。
但是,当我执行vercel --prod来创建生产部署时,它一直失败。
日志是这样的:

[16:48:49.455] Previous build cache not available
[16:48:49.684] Downloading 69 deployment files...
[16:48:50.586] Running "vercel build"
[16:48:51.246] Vercel CLI 28.10.0
[16:48:51.661] Installing dependencies...
[16:48:52.107] yarn install v1.22.17
[16:48:52.183] [1/4] Resolving packages...
[16:48:52.393] [2/4] Fetching packages...
[16:49:16.863] [3/4] Linking dependencies...
[16:49:31.972] [4/4] Building fresh packages...
[16:49:32.468] Done in 40.37s.
[16:49:32.503] Detected Next.js version: 13.1.1-canary.1
[16:49:32.505] Running "yarn run build"
[16:49:32.842] yarn run v1.22.17
[16:49:32.888] $ next build
[16:49:33.425] Attention: Next.js now collects completely anonymous telemetry regarding usage.
[16:49:33.425] This information is used to shape Next.js' roadmap and prioritize features.
[16:49:33.425] 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:
[16:49:33.425] https://nextjs.org/telemetry
[16:49:33.426] 
[16:49:33.588] info  - Linting and checking validity of types...
[16:49:38.211] Failed to compile.
[16:49:38.212] 
[16:49:38.212] ./sanity/sanity.cli.ts:1:31
[16:49:38.212] Type error: Cannot find module 'sanity/cli' or its corresponding type declarations.
[16:49:38.212] 
[16:49:38.213] [0m[31m[1m>[22m[39m[90m 1 | [39m[36mimport[39m {defineCliConfig} [36mfrom[39m [32m'sanity/cli'[39m[0m
[16:49:38.213] [0m [90m   | [39m                              [31m[1m^[22m[39m[0m
[16:49:38.213] [0m [90m 2 | [39m[0m
[16:49:38.213] [0m [90m 3 | [39m[36mexport[39m [36mdefault[39m defineCliConfig({[0m
[16:49:38.213] [0m [90m 4 | [39m  api[33m:[39m {[0m
[16:49:38.253] error Command failed with exit code 1.
[16:49:38.254] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[16:49:38.283] Error: Command "yarn run build" exited with 1

我的包裹。

{
  "name": "portfolio-project",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@portabletext/react": "^2.0.0",
    "@sanity/image-url": "^1.0.1",
    "@types/node": "18.11.12",
    "@types/react": "18.0.26",
    "@types/react-dom": "18.0.9",
    "@vercel/analytics": "^0.1.6",
    "eslint": "8.29.0",
    "eslint-config-next": "13.0.6",
    "framer-motion": "^7.6.19",
    "next": "13.0.6",
    "next-sanity": "^3.1.5",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-simple-typewriter": "^5.0.1",
    "react-social-icons": "^5.15.0",
    "typescript": "4.9.4"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.19",
    "tailwind-scrollbar": "^2.0.1",
    "tailwindcss": "^3.2.4"
  }
}

sanity文件夹中的sanity package.json:

{
  "name": "portfolio-project",
  "private": true,
  "version": "1.0.0",
  "main": "package.json",
  "license": "UNLICENSED",
  "scripts": {
    "dev": "sanity dev",
    "start": "sanity start",
    "build": "sanity build",
    "deploy": "sanity deploy",
    "deploy-graphql": "sanity graphql deploy"
  },
  "keywords": [
    "sanity"
  ],
  "dependencies": {
    "@sanity/vision": "^3.0.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-is": "^18.2.0",
    "sanity": "^3.0.0",
    "styled-components": "^5.2.0"
  },
  "devDependencies": {
    "@sanity/eslint-config-studio": "^2.0.1",
    "eslint": "^8.6.0",
    "prettier": "^2.8.1",
    "typescript": "^4.0.0"
  },
  "prettier": {
    "semi": false,
    "printWidth": 100,
    "bracketSpacing": false,
    "singleQuote": true
  }
}

有人有同样的问题吗?它一直说它找不到模块'sanity/cli'或其相应的类型声明。
我试着按照别人的建议将Next.js版本升级到最新版本(next@canary),将@sanity/cli安装到本地等等,但没有发现任何运气。
如果有人有线索,请帮忙!!!

nlejzf6q

nlejzf6q1#

解决我的问题的方法是将此函数添加到next.config.js

eslint: {
    // Warning: This allows production builds to successfully complete even if
    // your project has ESLint errors.
    ignoreDuringBuilds: true
  },
  typescript: {
    // !! WARN !!
    // Dangerously allow production builds to successfully complete even if
    // your project has type errors.
    // !! WARN !!
    ignoreBuildErrors: true
  }

请注意,这不会破坏代码中的任何内容。我认为这可能是因为NextJS项目中包含了typescript和Sanity项目。或者可能是因为在进行下一次构建时,它仍然没有安装Sanity package.json的依赖项。

相关问题