Skip to content

Instantly share code, notes, and snippets.

@OlehDutchenko
Last active April 2, 2022 19:19
Show Gist options
  • Save OlehDutchenko/c561d59c1ec9dbcc9414f6e4274c706d to your computer and use it in GitHub Desktop.
Save OlehDutchenko/c561d59c1ec9dbcc9414f6e4274c706d to your computer and use it in GitHub Desktop.
Example for the next.config.js to enable typescript errors check in dev mode
// -----------------------------------------------------------------------------
// Deps
// -----------------------------------------------------------------------------
const fromCWD = require('from-cwd');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const PnpWebpackPlugin = require('pnp-webpack-plugin');
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
// -----------------------------------------------------------------------------
// Next.js config
// @see {@link https://nextjs.org/docs/api-reference/next.config.js/introduction}
// -----------------------------------------------------------------------------
module.exports = (phase, { defaultConfig }) => ({
pageExtensions: ['tsx', 'ts'],
webpack(config, { isServer }) {
if (phase === PHASE_DEVELOPMENT_SERVER && !isServer) {
config.plugins.push(
new ForkTsCheckerWebpackPlugin(
PnpWebpackPlugin.forkTsCheckerOptions({
async: false,
useTypescriptIncrementalApi: true,
checkSyntacticErrors: true,
tsconfig: fromCWD('./tsconfig.json'),
reportFiles: ['**', '!**/__tests__/**', '!**/?(*.)(spec|test).*'],
compilerOptions: { isolatedModules: true, noEmit: true },
silent: true,
formatter: 'codeframe'
})
)
);
}
return config;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment