Sanity中使用code-input插件遇Unknown type: code错误求助
解决Sanity中"Unknown type: code"错误
检查插件注册配置
Sanity v2版本不会自动识别已安装的插件,必须在配置文件中显式注册:
- 打开项目根目录的
sanity.json,在plugins数组中添加code-input:
{ "plugins": [ // 其他已存在的插件 "code-input" ] }
如果使用JS配置文件(如sanity.config.js),则添加:
import { codeInput } from '@sanity/code-input' export default { // 其他配置项 plugins: [ // 其他插件 codeInput() ] }
确认插件与Sanity版本兼容
你的Sanity版本为2.30.6,需安装对应v2系列的@sanity/code-input插件,避免版本不匹配:
yarn add @sanity/code-input@^2.0.0
重启开发服务器
修改配置文件后必须重启Sanity本地服务,否则新插件不会被加载:
sanity start
校验schema字段定义
确保字段的type值拼写正确(必须全小写为code),示例正确结构:
{ name: 'exampleUsage', title: 'Example usage', type: 'code', // 可选:添加语言配置 options: { language: 'javascript', languageAlternatives: [ {title: 'JavaScript', value: 'javascript'}, {title: 'HTML', value: 'html'} ] } }
内容的提问来源于stack exchange,提问作者NexCodes
相关产品推荐
相关产品推荐

