Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Live Typescript Checking with Next.JS

The only way to check for TypeScript errors with Next.JS is to use npm run build (or yarn build).

If you run npm run dev, it won't show you TypeScript errors, which sucks because it would be nicer to see them in the Terminal window while you're developing.

Is there any way to make npm run dev show TS errors?

FYI - I REALLY don't like using my IDE to work with TS errors. Just my personal preference. I prefer to see them in the terminal window with all the other errors.

like image 543
Ben Avatar asked Dec 30 '25 05:12

Ben


2 Answers

You can do something like this if you are using TS4+:

// package.json

{
  "scripts": {
    "dev": "next dev",
    "dev:ts": "yarn dev & yarn ts:watch", // <-- or use concurrently here
                                          // npmjs.com/package/concurrently
    "ts": "tsc --noEmit --incremental",
    "ts:watch": "yarn ts --watch"
  },

  // ...
}

You can also provide custom webpack config like this:

// next.config.js

module.exports = {
  webpack(config, { dev }) {
    if (dev) {
      const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
      config.plugins.push(new ForkTsCheckerWebpackPlugin());
    }
    return config;
  },
};

The feature request is being tracked here.

like image 59
brc-dd Avatar answered Jan 03 '26 12:01

brc-dd


Unfortunately, as of Next.js v9.4, development typescript checks are disabled since these checks significantly slow the development process. Tim Neutkens states they expect this to happen on the IDE.

And currently, there is no way to re-enable these checks.

like image 22
Gokhan Sari Avatar answered Jan 03 '26 11:01

Gokhan Sari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!