Usage with custom input components that depend on browser APIs #207
Replies: 1 comment 5 replies
-
Hey @danmichaelo!
As you were alluding to, this occurs when node runs browser-dependent code during schema extraction. This problem isn't unique to sanity-codegen (e.g. next.js users experience this with SSR) but the schema's default environment is a single-page app run only the browser so it'll happen more often than other environments. Right now In the future I want to add an Could you try this? import { SanityCodegenConfig, defaultBabelOptions } from 'sanity-codegen';
const config: SanityCodegenConfig = {
schemaPath: './sanity/schemas/schema',
outputPath: './generatedTypes/modelTypes.ts',
babelOptions: {
...defaultBabelOptions,
plugins: [
// taken from here:
// https://github.com/ricokahler/sanity-codegen/blob/c0761ea8292a9d89a5072e173694f96b4e06f120/src/cli.ts#L22-L44
[
'module-resolver',
{
root: ['.'],
alias: {
'part:@sanity/base/schema-creator':
'sanity-codegen/schema-creator-shim',
'all:part:@sanity/base/schema-type':
'sanity-codegen/schema-type-shim',
'part:@sanity/base/schema-type': 'sanity-codegen/schema-type-shim',
'^part:.*': 'sanity-codegen/no-op',
'^config:.*': 'sanity-codegen/no-op',
'^all:part:.*': 'sanity-codegen/no-op',
// 👇👇👇
'your-module-to-alias': 'sanity-codegen/no-op',
// 👆👆👆
},
},
],
// used to resolve css module imports that are allowed in sanity projects
'css-modules-transform',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-numeric-separator',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
],
},
};
export default config; Also: if you're willing to help test, maybe we can try to tackle #67 together? Lmk! |
Beta Was this translation helpful? Give feedback.
-
Hi! We've just getting started with creating our own custom input components for a Next.js Sanity Studio project, more specifically a date picker based on https://react-day-picker.js.org/ , but this caused
sanity-codegen
to stop working because there is some dependency on a browser API:Guess we're not the first ones running into this problem, but didn't find a solution when googling, so would be awesome if someone could share how they worked around this 🙏 Some kind of lazy-loading perhaps?
Our
sanity-codegen.config.ts
is really simple atm.:Beta Was this translation helpful? Give feedback.
All reactions