
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see you're running into the "Schema.compile is not a function" error when trying to import content. This is a common issue that happens when using the older @sanity/schema package API, which has changed significantly between Sanity Studio versions.
The Schema.compile method was part of the v2 API. Here's how to fix it depending on your situation:
If you're on Studio v3 or v4, you should use the modern schema definition approach. Instead of compiling schemas manually with @sanity/schema, schemas are now defined using defineType and defineField:
import {defineType, defineField} from 'sanity'
export const mySchemaType = defineType({
name: 'myDocument',
type: 'document',
fields: [
defineField({
name: 'title',
type: 'string'
})
]
})For content imports/migrations, use the modern CLI migration tool:
npx sanity@latest migration createThis gives you a migration script where you can use defineMigration without needing to manually compile schemas.
If you're specifically working with Portable Text conversion or maintaining v2 code, the correct import syntax is:
import Schema from '@sanity/schema'
const defaultSchema = Schema.compile({
name: 'mySchema',
types: [
// your schema types here
]
})The key issue is the import syntax. You need to import the default export from @sanity/schema, not a named export:
✅ Correct: import Schema from '@sanity/schema'
❌ Wrong: import { Schema } from '@sanity/schema'
The Portable Text documentation shows this pattern for HTML-to-Portable-Text conversion:
import Schema from '@sanity/schema'
import blockTools from '@portabletext/block-tools'
const defaultSchema = Schema.compile({
name: 'default',
types: schemaTypes
})
const blockContentType = defaultSchema.get('blogPost')
.fields.find(field => field.name === 'body').type
const blocks = blockTools.htmlToBlocks(
'<html><body><h1>Hello world!</h1></body></html>',
blockContentType
)import Schema from '@sanity/schema' (default import)@sanity/schema for most use cases@sanity/schema is installed: npm install @sanity/schemaIf you're migrating content to Sanity, I'd strongly recommend using the modern migration tools (npx sanity migration create) rather than manually compiling schemas. This approach is better supported, has better error handling, and includes features like dry-run mode and validation.
Could you share what version of Sanity Studio you're using and what you're trying to accomplish with the import? That would help me give you more specific guidance!
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store