typescriptnext.js

Disable TypeScript from checking types validity when building for production


I am using using Next.js with TypeScript for a small project. I am wondering if it's possible to disable types validity checks when I run npm run build considering type checking happened during npm run dev. Plus this will help to build production build without TypeScript package which is not used in production.


Solution

  • Open next.config.js and enable the ignoreBuildErrors option in the typescript config:

    module.exports = {
      typescript: {
        // !! WARN !!
        // Dangerously allow production builds to successfully complete even if
        // your project has type errors.
        // !! WARN !!
        ignoreBuildErrors: true,
      },
    }
    

    More info on the docs: https://nextjs.org/docs/api-reference/next.config.js/ignoring-typescript-errors