typescriptnext.jssanity

Sanity npm package throws type error on build


As the title says, I use next-sanity for my Next.js blog. I recently wanted to update all npm packages. Now I can´t run npm run build as the one of the dependncies itself throws a type error as follows:

./node_modules/@sanity/types/lib/dts/src/index.d.ts:756:3
Type error: Type parameter declaration expected.

  754 |  */
  755 | export declare function defineArrayMember<
> 756 |   const TType extends string | IntrinsicTypeName, // IntrinsicTypeName here improves autocompletion in _some_ IDEs (not VS Code atm)
      |   ^
  757 |   const TName extends string,
  758 |   TSelect extends Record<string, string> | undefined,
  759 |   TPrepareValue extends Record<keyof TSelect, any> | undefined,

I tried manually adding older versions of the package in question but I could not find a suitable solution so far. Deleting node_modules or package.json and then running npm iagain also did nothing to change the outcome.

Has anyone also had the same problem?

I had this problem after I ran npm update, then I fixed the issues due to some changes mentioned in the docs. But the main issue is, that previously normally functioning features are not working despite no change inside the docs suggesting I did something wrong.

I use next 14.1.0, next-sanity 8.5.0 and sanity 3.36.2


Solution

  • I had the same error after I upgraded my existing project from next js version 12, and converted it to typescript. Next automatically created a tsconfig.json file for me, however it did not install typescript in the devDependencies. After I installed typescript using the following command:

    npm install -D typescript
    

    The issue was fixed. Hope this helps!