首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用keystone添加文档字段-下一个错误:字段未定义任何适配器

使用keystone添加文档字段-下一个错误:字段未定义任何适配器
EN

Stack Overflow用户
提问于 2021-05-04 07:32:02
回答 1查看 180关注 0票数 0

当我为我的列表之一使用字段类型document时,如下所示:

代码语言:javascript
复制
import { list } from '@keystone-next/keystone/schema';
import {
  text,
  timestamp,
  select,
} from '@keystone-next/fields';
import { document } from '@keystone-next/fields-document';



export const Post = list({
  fields: {
    title: text(),
    status: select({
      options: [
        { label: 'Published', value: 'published' },
        { label: 'Draft', value: 'draft' },
      ],
      ui: {
        displayMode: 'segmented-control',
      },
    }),
    content: document(),
    publishDate: timestamp(),
  },
});

但是,该项目无法编译。以下是错误消息:

代码语言:javascript
复制
 Error: The type given for the 'Post.content' field doesn't define any adapters.
at  /Users/johndoe/Projects/MyBlog/backend/node_modules/@keystonejs/keystone/lib/ListTypes/list.js:199:15
    at Array.forEach (<anonymous>)
    at List.initFields (/Users/johndoe/Projects/MyBlog/backend/node_modules/@keystonejs/keystone/lib/ListTypes/list.js:185:43)
    at Keystone.createList (/Users/johndoe/Projects/MyBlog/backend/node_modules/@keystonejs/keystone/lib/Keystone/index.js:296:10)
    at /Users/johndoe/Projects/MyBlog/backend/node_modules/@keystone-next/keystone/dist/initConfig-34e7aba3.cjs.dev.js:663:16
    at Array.forEach (<anonymous>)
    at createKeystone (/Users/johndoe/Projects/MyBlog/backend/node_modules/@keystone-next/keystone/dist/initConfig-34e7aba3.cjs.dev.js:654:25)
    at Object.createSystem (/Users/johndoe/Projects/MyBlog/backend/node_modules/@keystone-next/keystone/dist/initConfig-34e7aba3.cjs.dev.js:695:20)
    at initKeystone (/Users/johndoe/Projects/MyBlog/backend/node_modules/@keystone-next/keystone/scripts/dist/keystone.cjs.dev.js:374:20)
    at Server.<anonymous> (/Users/johndoe/Projects/MyBlog/backend/node_modules/@keystone-next/keystone/scripts/dist/keystone.cjs.dev.js:405:5)
    at Object.onceWrapper (node:events:484:28)
    at Server.emit (node:events:378:20)
    at emitListeningNT (node:net:1344:10)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)
npm ERR! code 1

如果我用content: text()替换content: document(),项目将成功编译。

以下是来自package.json的相关依赖项:

代码语言:javascript
复制
 "@keystone-next/admin-ui": "^8.0.1",
    "@keystone-next/auth": "^14.0.0",
    "@keystone-next/cloudinary": "^2.0.9",
    "@keystone-next/fields": "^4.1.1",
    "@keystone-next/fields-document": "^5.0.0",
    "@keystone-next/keystone": "^9.3.0",
    "@keystone-next/types": "^12.0.0",
    "@keystonejs/server-side-graphql-client": "^1.1.2",
    "@types/nodemailer": "^6.4.0",
    "dotenv": "^8.2.0",
    "next": "^10.0.5",
    "nodemailer": "^6.4.17",
    "react": "^16.14.0",
    "react-dom": "^16.14.0",
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-06 23:45:22

您可能正在使用react的旧版本,Keystone-next当前使用react 17.02。尝试升级所有依赖项,尝试yarn upgrade-interactive --latest将所有依赖项升级到最新版本。

还有。你必须提供一些基本的选项,以便能够正确使用文档字段,至少document({formatting: true})配置是所需的,否则它将只是没有格式的文本字段。

下面是不需要关系或其他复杂设置的格式化示例。

代码语言:javascript
复制
content: document({        
        formatting: true,
        layouts: [
          [1, 1],
          [1, 1, 1],
          [2, 1],
          [1, 2],
          [1, 2, 1],
        ],
        links: true,
        dividers: true,
      }),

这将生成带有以下工具栏的文档域

有关更复杂的示例,包括使用自定义文档字段块,请参见- https://github.com/keystonejs-contrib/keystonejs-document-demo

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67376991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档