【问题标题】:Problem Deploying a Next JS + Sanity Project to Vercel将下一个 JS + Sanity 项目部署到 Vercel 时出现问题
【发布时间】:2023-02-24 03:49:22
【问题描述】:

我在一个项目中,理智地使用了 nextjs,但在几乎完成我的项目之后,我只是看不到任何部署它的方法。学习理智花了很多时间,但如果我不能在任何地方使用它,那还有什么意义。

我安装了 vercel 并运行vercel build 这是它向我展示的内容:

[17:27:01.100] Retrieving list of deployment files...
[17:27:01.382] Previous build cache not available
[17:27:01.637] Downloading 75 deployment files...
[17:27:02.283] Running "vercel build"
[17:27:02.784] Vercel CLI 28.10.0
[17:27:03.095] Installing dependencies...
[17:27:11.072] 
[17:27:11.073] added 229 packages in 8s
[17:27:11.073] 
[17:27:11.073] 32 packages are looking for funding
[17:27:11.073]   run `npm fund` for details
[17:27:11.086] Detected Next.js version: 13.0.7
[17:27:11.089] Detected `package-lock.json` generated by npm 7+...
[17:27:11.089] Running "npm run build"
[17:27:11.396] 
[17:27:11.396] > ptfolio@0.1.0 build
[17:27:11.396] > next build
[17:27:11.396] 
[17:27:11.838] Attention: Next.js now collects completely anonymous telemetry regarding usage.
[17:27:11.839] This information is used to shape Next.js' roadmap and prioritize features.
[17:27:11.839] 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:
[17:27:11.839] https://nextjs.org/telemetry
[17:27:11.839] 
[17:27:11.968] info  - Linting and checking validity of types...
[17:27:15.476] Failed to compile.
[17:27:15.476] 
[17:27:15.476] ./sanity/sanity.cli.ts:1:31
[17:27:15.477] Type error: Cannot find module 'sanity/cli' or its corresponding type declarations.
[17:27:15.477] 
[17:27:15.477] [0m[31m[1m>[22m[39m[90m 1 | [39m[36mimport[39m {defineCliConfig} [36mfrom[39m [32m'sanity/cli'[39m[0m
[17:27:15.477] [0m [90m   | [39m                              [31m[1m^[22m[39m[0m
[17:27:15.477] [0m [90m 2 | [39m[0m
[17:27:15.477] [0m [90m 3 | [39m[36mexport[39m [36mdefault[39m defineCliConfig({[0m
[17:27:15.477] [0m [90m 4 | [39m  api[33m:[39m {[0m
[17:27:15.520] Error: Command "npm run build" exited with 1

我已经尝试安装 sanity cli、sanity client、sanity image url,尝试推送到 github 并从那里部署。不知道该怎么办了

编辑:这是我的 package.json 文件->

{
  "name": "ptfolio",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@heroicons/react": "^2.0.13",
    "@next/font": "13.0.7",
    "@portabletext/react": "^2.0.0",
    "@sanity/cli": "^3.1.2",
    "@sanity/client": "^3.4.1",
    "@sanity/image-url": "^1.0.1",
    "@types/node": "18.11.16",
    "@types/react": "18.0.26",
    "@types/react-dom": "18.0.9",
    "framer-motion": "^7.10.2",
    "git": "^0.1.5",
    "next": "13.0.7",
    "next-sanity": "^3.1.8",
    "next-sanity-image": "^5.0.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-hook-form": "^7.41.1",
    "react-simple-typewriter": "^5.0.1",
    "react-social-icons": "^5.15.0",
    "typescript": "4.9.4"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.20",
    "tailwind-scrollbar": "^2.0.1",
    "tailwindcss": "^3.2.4"
  }
}

【问题讨论】:

  • 你能展示 packages.json 文件吗?
  • @Honorablecon 我添加了我的 package.json 文件
  • @TheFlashExs 你有没有找到解决这个问题的方法?

标签: next.js deployment vercel sanity


【解决方案1】:

确保没有在全局或 devDependencies 中安装 sanity/cli 依赖项。

【讨论】:

    【解决方案2】:

    我找到了解决方案,我遇到了同样的问题。

    添加一些环境变量(进入 Vercel 项目去设置):

    NEXT_PUBLIC_SANITY_PROJECT_ID
    

    NEXT_PUBLIC_BASE_URL
    

    具有正确的值。

    不要忘记 url 的“https://”。

    让我知道它是否解决了你这边的问题

    【讨论】:

      猜你喜欢
      • 2022-01-25
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 2023-01-31
      • 2022-07-15
      • 2022-09-30
      • 2022-01-19
      • 2022-11-13
      相关资源
      最近更新 更多