sanity-codegen icon indicating copy to clipboard operation
sanity-codegen copied to clipboard

TypeError: types.filter is not a function

Open lasnab opened this issue 2 years ago • 6 comments

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).

lasnab avatar Jan 16 '23 00:01 lasnab

I'm having the same problem 😭

RobPrecious avatar Jan 18 '23 11:01 RobPrecious

Does anyone have a solution yet?

Spectari-code avatar Jan 21 '23 12:01 Spectari-code

This seemed to work for me https://github.com/ricokahler/sanity-codegen/issues/272#issuecomment-1241092032

sohailykhan94 avatar Jan 22 '23 19:01 sohailykhan94

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;

MaffooBristol avatar Feb 18 '23 12:02 MaffooBristol

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.

pencilcheck avatar May 17 '23 07:05 pencilcheck

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;

Worked for me, king! 👑

mammadmammadli avatar Jun 18 '23 21:06 mammadmammadli