Vercel构建错误:看起来你正在使用与’@sanity/preview-kit/client’预期不符的选项。

huangapple go评论113阅读模式
英文:

Vercel Build Error: It looks like you're using options meant for '@sanity/preview-kit/client'

问题

抱歉,这是您要翻译的部分:

错误:看起来您正在使用针对'@sanity/preview-kit/client'的选项,例如'encodeSourceMapAtPath'、'encodeSourceMap'、'studioUrl'和'logger'。确保您正在使用正确的导入。

我在我的sanity客户端配置中有"studioUrl"参数,但我将其删除,并将其推送到GitHub供Vercel构建,但它仍然抛出相同的错误。

这是我的sanity客户端配置:

import { createClient } from "next-sanity";
import imageUrlBuilder from '@sanity/image-url';

export const client = createClient({
    projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
    dataset: "production",
    apiVersion: "2022-03-25",
    token: process.env.NEXT_PUBLIC_SANITY_API_TOKEN,
    useCdn: true,
});
  
const builder = imageUrlBuilder(client);

export const urlFor = (source) => builder.image(source);

我尝试在本地构建我的项目,没有错误。

英文:

Hi Im having an odd issue with Vercel deployment because of sanity, this is the Vercel build error:

Error: It looks like you're using options meant for '@sanity/preview-kit/client', such as 'encodeSourceMapAtPath', 'encodeSourceMap', 'studioUrl' and 'logger'. Make sure you're using the right import.

I had "studioUrl" param in my sanity client config but I deleted it, and pushed it to Git Hub for Vercel to build but it keeps throwing the same error.

this is my sanity client config:

import { createClient } from "next-sanity";
import imageUrlBuilder from '@sanity/image-url';

export const client = createClient({
    projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
    dataset: "production",
    apiVersion: "2022-03-25",
    token: process.env.NEXT_PUBLIC_SANITY_API_TOKEN,
    useCdn: true,
  });
  
const builder = imageUrlBuilder(client);

export const urlFor = (source) => builder.image(source);


I tried to build my project locally and there is no error.

答案1

得分: 2

我更改了我的 sanityClient.ts 中的代码。

之前的代码:

import { createClient } from 'next-sanity'在此代码中出现错误

新代码:

import { createClient } from "@sanity/client"错误已解决
英文:

I change code in my sanityClient.ts

Previous Code

import { createClient } from 'next-sanity' (get error in this code)

New Code

import { createClient } from "@sanity/client" ( error solved)

答案2

得分: 1

我今天遇到了同样的问题。不确定这是何时发生的,因为我在两个不同的项目中都使用了相同的 next-sanity 版本,但在其中一个项目中,package-lock 中的 @sanity/cli 版本似乎是 5.4.2(正常工作的那个),而在另一个项目中是 6.1.7(这个不工作)。

为了解决这个问题,我不得不迁移到 next-sanity v5(目前是 5.4.2),并进行所需的更改(这是一小部分更改),详细说明在这个链接中,更详细的解释在这个页面中。

基本上,更改包括:

  • 通过 useLiveQuery 替换 usePreview 模式。
  • 移除 PreviewSuspense,因为它不再存在,用一个默认值返回时提供行为(现在 useLiveQuery 接受一个默认值,而不是返回 null)。
  • 创建一个接受预览令牌的小型 LiveQueryProvider。

所有这些步骤在上面的链接中都有更详细的解释,但简而言之就是这样。

如果无法更新版本,解决这个问题的另一种可能性是使用 pnpm 或 yarn 指定 @sanity/client 的版本(5.4.2),以使其与 next-sanity 4.3.3 兼容,但我没有尝试过这个来确认是否有效。

希望对你有所帮助!

英文:

I ran into the same issue today. Not sure when this happened because I'm using the same next-sanity version in 2 different projects, but in one of them the @sanity/cli version in package-lock seems to be 5.4.2 (the one that works) and in other project is 6.1.7 (this one doesn't work).

In order to fix the issue, I had to migrate to next-sanity v5 (currently 5.4.2) making the required changes (is a small set of changes) mentioned in this link which are better explained and detailed in this page.

Basically the changes consist on:

  • Replacing usePreview pattern by useLiveQuery.
  • Removing PreviewSuspense since it doesn't exist anymore and replace it by providing a a behavior when the default value is returned (useLiveQuery accepts a default value that will be returned now instead of null).
  • Creating a small LiveQueryProvider that accepts the preview token.

All this steps are better explained in the links above, but that's it in short.

Another possibility of resolving this problem in case of not being able to update the version could be to use pnpm or yarn to specify a version of @sanity/client (5.4.2) to make it work with next-sanity 4.3.3 but I didn't try this to confirm it works.

Hope it helps!

huangapple
  • 本文由 发表于 2023年7月13日 20:29:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679395.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定