Description
Describe the bug
When using custom icons (i use lucide-react) in Sanity schema definitions, typegen fails with an Reference Error. Failed to load config file, require is not defined. The custom icon type is not recognized by the type generation tools.
$ sanity schema extract --enforce-required-fields --path=./sanity/extract.json && sanity typegen generate
✗ Failed to extract schema, with enforced required fields
ReferenceError: Failed to load configuration file "C:/Users/<path>/sanity.config.ts
":
require is not defined
at file:///C:/Users/<path>/node_modules/lucide-react/dist/cjs/lucide-react.js:1
0:13
":
require is not defined
at file:///C:/Users/<path>/node_modules/lucide-react/dist/cjs/lucide-react.js:1
":
require is not defined
":
":
require is not defined
at file:///C:/Users/<path>/node_modules/lucide-react/dist/cjs/lucide-react.js:1
0:13
at Object.newLoader [as .js] (C:/Users/<path>/node_modules/esbuild-register/dis
t/node.js:2262:9)
at extensions..js (C:/Users/<path>/node_modules/esbuild-register/dist/node.js:4
833:24)
error Command failed with exit code 1.
To Reproduce
Steps to reproduce the behavior:
- Go to 'schemaTypes/schema.ts'
- Click on 'import and use HandPlatter icon'
- Open terminal and 'yarn run dev'
- See error
Expected behavior
typegen should recognize custom icons and generate types without errors.
Screenshots
Which versions of Sanity are you using?
@sanity/cli (global) 3.76.1 (latest: 3.76.3)
@sanity/image-url 1.1.0 (up to date)
@sanity/vision 3.76.1 (latest: 3.76.3)
sanity 3.76.1 (latest: 3.76.3)
What operating system are you using?
Windows 11 Pro (AtlasOS)
Which versions of Node.js / npm are you running?
Node: v22.14.0
Yarn: v1.22.22
Tested With: Node: 23.7.0 - 23.8.0, pnpm 9.15.7 - pnpm 10.4.0
Additional context
I am using the Markdown plugin in my Sanity schema. I tried disabling and re-enabling the plugin, but the issue persists. This error did not occur in previous versions of Sanity
. It seems to be related to the recent updates or changes in the type generation process.
Here’s how I integrated the Markdown plugin:
import { defineType } from 'sanity';
import { MarkdownIcon } from '@sanity/icons';
export default defineType({
name: 'content',
title: 'Content',
type: 'markdown',
icon: MarkdownIcon,
validation: (Rule) => Rule.required().min(500),
});
Security issue?
No
Activity