TypeError: types.filter is not a function
Hi all,
Getting a type error when running npx sanity-codegen. Followed the tutorial as described in the readme, double checked all the paths, dependencies and tried running in both with sanity-codegen.config.ts in the sanity app directory, and also having it in my project root directory, getting the same error. My project is organized as follows -
project -
- sanity-studio
- src
- other files for react
Note: React was initialized with typescript (so was sanity studio).
I'm having the same problem 😭
Does anyone have a solution yet?
This seemed to work for me https://github.com/ricokahler/sanity-codegen/issues/272#issuecomment-1241092032
TL;DR
The codegen plugin expects that the index file has a default export. The Sanity 3.0.0 generator gives a named export
Simply adding export default schemaTypes to the end of schemas/index.ts fixes this
Eg for me, I have this in schemas/index.ts:
import blockContent from './blockContent';
import category from './category';
import post from './post';
import author from './author';
export const schemaTypes = [
post,
author,
category,
blockContent,
];
export default schemaTypes;
Can't believe sanity didn't update this with their main package, I hope they fix this soon so it can work out of box.
TL;DR
The codegen plugin expects that the index file has a default export. The Sanity 3.0.0 generator gives a named export Simply adding
export default schemaTypesto the end ofschemas/index.tsfixes thisEg for me, I have this in schemas/index.ts:
import blockContent from './blockContent'; import category from './category'; import post from './post'; import author from './author'; export const schemaTypes = [ post, author, category, blockContent, ]; export default schemaTypes;
Worked for me, king! 👑