Help articles

Schema type is an ES module imported through require

Schema validation reports Type appears to be an ES6 module imported through CommonJS require - use an import statement or access the `.default` property.

Despite the wording, the check doesn't look for a require call. It fires when a value in your list of schema types has no name of its own but carries a default property that looks like a type definition. That happens when a module object reaches the schema instead of the type the module exports.

Given a schema type defined as a default export:

...the error appears if you register the module itself rather than its default export:

Import the default export instead:

If you can't change the import, reach into the default export where you register the type: types: [heroImage.default].

TypeScript rejects the module form at compile time, so this error usually surfaces in JavaScript studios, or where the list of types is assembled dynamically.

In Studio v2 the same error came from a CommonJS require call in a part:@sanity/base/schema-creator file. Studio v3 and later load schema modules as ESM, where require isn't available.

Was this page helpful?