tatethurston / nextjs-routes

Type safe routing for Next.js
MIT License
578 stars 21 forks source link

Generate .d.ts file during build also #164

Closed ecstrema closed 1 year ago

ecstrema commented 1 year ago

It seems that only next dev generates the file, but next build does not, so if I .gitignore the generated typings, build fails on CI.

I read in the readme that the route typings are generated during build also, but cannot reproduce this.

to reproduce

Since typings are not created, the typescript build fails if we

import type { Route } from "nextjs-routes";

expected

The file is also generated during build

tatethurston commented 1 year ago

@ecstrema the nextjs-routes.d.ts is generated into types/nextjs-routes.d.ts.

you can not gitignore this file because typechecking occurs before the build step runs in nextjs.

ecstrema commented 1 year ago

Hmm that's interesting... The best way might be to run the generating cli before build then...

ecstrema commented 1 year ago

So for those wanting a fix: here's what I did:

package.json:

{
"scripts": {
    "build": "nextjs-routes && next build",
    }
}

That way, you can add /@types/nextjs-routes.d.ts to .gitignore

tatethurston commented 1 year ago

Yep, alternatively you could disable typechecking in your next.config.js and then run tsc —noEmit after you build.