[英]Type error: Argument of type '{ projectId: string | undefined; }' is not assignable to parameter of type 'SCL| SPD | undefined'
I'm trying to deploy my project to Vercel but it seems to be giving me this error saying the following:我正在尝试将我的项目部署到 Vercel,但它似乎给我这个错误,说明以下内容:
Type error: Argument of type '{ dataset: string;类型错误:类型为“{ dataset: string; 的参数” projectId: string |
项目编号:字符串 | undefined;
不明确的; apiVersion: string;
api版本:字符串; useCdn: boolean;
使用CDN:boolean; }' is not assignable to parameter of type 'SanityClientLike |
}' 不可分配给 'SanityClientLike | 类型的参数SanityProjectDetails |
SanityProject详情 | undefined'.
不明确的'。 Type '{ dataset: string;
输入'{数据集:字符串; projectId: string |
项目编号:字符串 | undefined;
不明确的; apiVersion: string;
api版本:字符串; useCdn: boolean;
使用CDN:boolean; }' is not assignable to type 'SanityProjectDetails'.
}' 不可分配给类型 'SanityProjectDetails'。 Types of property 'projectId' are incompatible.
属性“projectId”的类型不兼容。 Type 'string |
输入'字符串| undefined' is not assignable to type 'string'.
undefined' 不可分配给类型 'string'。
Type 'undefined' is not assignable to type 'string'.类型“undefined”不可分配给类型“string”。
import { createClient } from "next-sanity";
import createImageUrlBuilder from '@sanity/image-url';
export const config = {
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || 'production',
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
apiVersion: '2021-03-25',
useCdn: process.env.NODE_ENV === 'production',
};
export const sanityClient = createClient(config);
export const urlFor = (source: any) => createImageUrlBuilder(config).image(source);
It's saying the error lies within the line createImageUrlBuilder(config).它说错误在于 createImageUrlBuilder(config) 行。 I'm not sure on what is wrong with this line.
我不确定这条线有什么问题。 If anyone knows how to fix this, I will appreaciate it so much.
如果有人知道如何解决这个问题,我会非常感激。
In your config add an OR condition with empty string value for projectId在您的配置中为 projectId 添加一个空字符串值的 OR 条件
export const config = {
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || 'production',
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID || '',
apiVersion: '2021-03-25',
useCdn: process.env.NODE_ENV === 'production',
};
You must put OR condition after projectId您必须在 projectId 之后放置 OR 条件
import { createClient } from "next-sanity";
import createImageUrlBuilder from "@sanity/image-url";
export const config = {
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || "production",
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID || "",
apiVersion: "2021-03-25",
useCdn: process.env.NODE_ENV === "production",
};
export const sanityClient = createClient(config);
export const urlFor = (source: any) => {
createImageUrlBuilder(config).image(source);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.