Sanity 配置必须包含`projectId`

问题描述 投票:0回答:1

这是错误:

Configuration must contain `projectId`
    at initConfig (http://localhost:3001/static/js/bundle.js:65087:53)
    at _SanityClient2.config (http://localhost:3001/static/js/bundle.js:65901:101)
    at new _SanityClient2 (http://localhost:3001/static/js/bundle.js:65888:299)
    at createClient (http://localhost:3001/static/js/bundle.js:66026:29)
    at http://localhost:3001/static/js/bundle.js:66036:36
    at ./src/components/sections/featured/featured.jsx (http://localhost:3001/static/js/bundle.js:1328:75)
    at options.factory (http://localhost:3001/static/js/bundle.js:160931:31)
    at __webpack_require__ (http://localhost:3001/static/js/bundle.js:160330:32)
    at fn (http://localhost:3001/static/js/bundle.js:160589:21)
    at ./src/pages/home/home.jsx (http://localhost:3001/static/js/bundle.js:2657:96)

这是我的client.js

import sanityClient from "@sanity/client";

export default sanityClient({
    projectId: 'twxbdh4g',
    dataset: "production",
    token: process.env.NEXT_PUBLIC_SANITY_TOKEN,
    apiVersion: '2024-04-25',
    useCdn: true,
})

我到处都找过了,但找不到解决方案,当我添加新的理智内容块时,会弹出此错误。

添加了 CORS 源并允许凭据。

reactjs content-management-system sanity
1个回答
0
投票

我快速浏览了文档。

您正在使用默认导入:

import sanityClient from "@sanity/client";

标记为折旧的: /**

  • @公众
  • @deprecated 使用命名导出
    createClient
    而不是
    default
    导出 */

所以你应该使用 `import {createClient} from '@sanity/client';

© www.soinside.com 2019 - 2024. All rights reserved.