Last active
April 2, 2022 19:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ----------------------------------------------------------------------------- | |
// 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