Unlock seamless workflows and faster delivery with our latest releases – get the details

Schema type is ES Module but imported through require

This happens when you have a schema type definition in a file like the following:

export default {
  // ... type definition here...
}

...but import it using CommonJS require:

import createSchema from 'part:@sanity/base/schema-creator'

export default createSchema({
  name: 'test-examples',
  types: schemaTypes.concat([
    // ... your types ...
    require('./someTypeDef.js')
  ])
})

The best solution is to use an import statement instead of require:

import createSchema from 'part:@sanity/base/schema-creator'
import someTypeDef from './someTypeDef'

export default createSchema({
  name: 'test-examples',
  types: schemaTypes.concat([
    // ... your types ...
    someTypeDef
  ])
})

Was this article helpful?