Adding document field with keystone-next error: field doesn't define any adapters

Adding document field with keystone-next error: field doesn't define any adapters

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

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(),
  },
});

但是,项目编译失败。这是错误消息:

 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 的相关依赖项:

 "@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",

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

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

这里是示例格式,不需要关系或其他复杂的设置。

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