Unverified Commit 9c799550 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Strip out dead code for `ignoreDevErrors` (#12941)

parent 7f28e8bf
......@@ -4,23 +4,9 @@ description: Next.js reports TypeScript errors by default. Learn to opt-out of t
# Ignoring TypeScript Errors
Next.js reports TypeScript errors by default. If you don't want to leverage this behavior and prefer something else instead, like your editor's integration, you may want to disable it.
Next.js fails your **production build** (`next build`) when TypeScript errors are present in your project.
Open `next.config.js` and enable the `ignoreDevErrors` option in the `typescript` config:
```js
module.exports = {
typescript: {
ignoreDevErrors: true,
},
}
```
Next.js will still fail your **production build** (`next build`) when TypeScript errors are present in your project.
---
If you'd like Next.js to dangerously produce production code even when your application has errors, you can also disable error reports for builds.
If you'd like Next.js to dangerously produce production code even when your application has errors, you can disable the built-in type checking step.
> Be sure you are running type checks as part of your build or deploy process, otherwise this can be very dangerous.
......@@ -32,9 +18,6 @@ module.exports = {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
//
// This option is rarely needed, and should be reserved for advanced
// setups. You may be looking for `ignoreDevErrors` instead.
// !! WARN !!
ignoreBuildErrors: true,
},
......
import chalk from 'next/dist/compiled/chalk'
import stripAnsi from 'next/dist/compiled/strip-ansi'
import textTable from 'next/dist/compiled/text-table'
import createStore from 'next/dist/compiled/unistore'
import stripAnsi from 'next/dist/compiled/strip-ansi'
import formatWebpackMessages from '../../client/dev/error-overlay/format-webpack-messages'
import { OutputState, store as consoleStore } from './store'
import forkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import { NormalizedMessage } from 'fork-ts-checker-webpack-plugin/lib/NormalizedMessage'
import { createCodeframeFormatter } from 'fork-ts-checker-webpack-plugin/lib/formatter/codeframeFormatter'
export function startedDevelopmentServer(appUrl: string) {
consoleStore.setState({ appUrl })
......@@ -28,10 +24,7 @@ type CompilerDiagnostics = {
type WebpackStatus =
| { loading: true }
| ({
loading: false
typeChecking: boolean
} & CompilerDiagnostics)
| ({ loading: false } & CompilerDiagnostics)
type AmpStatus = {
message: string
......@@ -54,7 +47,6 @@ type BuildStatusStore = {
enum WebpackStatusPhase {
COMPILING = 1,
COMPILED_WITH_ERRORS = 2,
TYPE_CHECKING = 3,
COMPILED_WITH_WARNINGS = 4,
COMPILED = 5,
}
......@@ -66,9 +58,6 @@ function getWebpackStatusPhase(status: WebpackStatus): WebpackStatusPhase {
if (status.errors) {
return WebpackStatusPhase.COMPILED_WITH_ERRORS
}
if (status.typeChecking) {
return WebpackStatusPhase.TYPE_CHECKING
}
if (status.warnings) {
return WebpackStatusPhase.COMPILED_WITH_WARNINGS
}
......@@ -155,23 +144,9 @@ buildStore.subscribe(state => {
true
)
} else {
let { errors, warnings, typeChecking } = status
let { errors, warnings } = status
if (errors == null) {
if (typeChecking) {
consoleStore.setState(
{
...partialState,
loading: false,
typeChecking: true,
errors,
warnings,
} as OutputState,
true
)
return
}
if (Object.keys(amp).length > 0) {
warnings = (warnings || []).concat(formatAmpMessages(amp) || [])
if (!warnings.length) warnings = null
......@@ -219,9 +194,7 @@ export function ampValidation(
export function watchCompilers(
client: import('webpack').Compiler,
server: import('webpack').Compiler,
enableTypeCheckingOnClient: boolean,
onTypeChecked: (diagnostics: CompilerDiagnostics) => void
server: import('webpack').Compiler
) {
if (previousClient === client && previousServer === server) {
return
......@@ -235,56 +208,12 @@ export function watchCompilers(
function tapCompiler(
key: string,
compiler: any,
hasTypeChecking: boolean,
onEvent: (status: WebpackStatus) => void
) {
let tsMessagesPromise: Promise<CompilerDiagnosticsWithFile> | undefined
let tsMessagesResolver: (diagnostics: CompilerDiagnosticsWithFile) => void
compiler.hooks.invalid.tap(`NextJsInvalid-${key}`, () => {
tsMessagesPromise = undefined
onEvent({ loading: true })
})
if (hasTypeChecking) {
const typescriptFormatter = createCodeframeFormatter({})
compiler.hooks.beforeCompile.tap(`NextJs-${key}-StartTypeCheck`, () => {
tsMessagesPromise = new Promise(resolve => {
tsMessagesResolver = msgs => resolve(msgs)
})
})
forkTsCheckerWebpackPlugin
.getCompilerHooks(compiler)
.receive.tap(
`NextJs-${key}-afterTypeScriptCheck`,
(diagnostics: NormalizedMessage[], lints: NormalizedMessage[]) => {
const allMsgs = [...diagnostics, ...lints]
const format = (message: NormalizedMessage) =>
typescriptFormatter(message, true)
const errors = allMsgs
.filter(msg => msg.severity === 'error')
.map(d => ({
file: (d.file || '').replace(/\\/g, '/'),
message: format(d),
}))
const warnings = allMsgs
.filter(msg => msg.severity === 'warning')
.map(d => ({
file: (d.file || '').replace(/\\/g, '/'),
message: format(d),
}))
tsMessagesResolver({
errors: errors.length ? errors : null,
warnings: warnings.length ? warnings : null,
})
}
)
}
compiler.hooks.done.tap(
`NextJsDone-${key}`,
(stats: import('webpack').Stats) => {
......@@ -299,72 +228,17 @@ export function watchCompilers(
onEvent({
loading: false,
typeChecking: hasTypeChecking,
errors: hasErrors ? errors : null,
warnings: hasWarnings ? warnings : null,
})
const typePromise = tsMessagesPromise
if (!hasErrors && typePromise) {
typePromise.then(typeMessages => {
if (typePromise !== tsMessagesPromise) {
// a new compilation started so we don't care about this
return
}
const reportFiles = stats.compilation.modules
.map(m => (m.resource || '').replace(/\\/g, '/'))
.filter(Boolean)
let filteredErrors = typeMessages.errors
? typeMessages.errors
.filter(({ file }) => file && reportFiles.includes(file))
.map(({ message }) => message)
: null
if (filteredErrors && filteredErrors.length < 1) {
filteredErrors = null
}
let filteredWarnings = typeMessages.warnings
? typeMessages.warnings
.filter(({ file }) => file && reportFiles.includes(file))
.map(({ message }) => message)
: null
if (filteredWarnings && filteredWarnings.length < 1) {
filteredWarnings = null
}
stats.compilation.errors.push(...(filteredErrors || []))
stats.compilation.warnings.push(...(filteredWarnings || []))
const {
errors: newErrors,
warnings: newWarnings,
} = formatWebpackMessages(
stats.toJson({ all: false, warnings: true, errors: true })
)
onTypeChecked({
errors: newErrors?.length ? newErrors : null,
warnings: newWarnings?.length ? newWarnings : null,
})
onEvent({
loading: false,
typeChecking: false,
errors: filteredErrors,
warnings: hasWarnings
? [...warnings, ...(filteredWarnings || [])]
: filteredWarnings,
})
})
}
}
)
}
tapCompiler('client', client, enableTypeCheckingOnClient, status =>
tapCompiler('client', client, status =>
buildStore.setState({ client: status })
)
tapCompiler('server', server, false, status =>
tapCompiler('server', server, status =>
buildStore.setState({ server: status })
)
......
......@@ -229,9 +229,8 @@ export default async function getBaseWebpackConfig(
const useTypeScript = Boolean(
typeScriptPath && (await fileExists(tsConfigPath))
)
const ignoreTypeScriptErrors = dev
? Boolean(isReactRefreshEnabled || config.typescript?.ignoreDevErrors)
: Boolean(config.typescript?.ignoreBuildErrors)
const ignoreTypeScriptErrors =
dev || Boolean(config.typescript?.ignoreBuildErrors)
let jsConfig
// jsconfig is a subset of tsconfig
......@@ -948,13 +947,14 @@ export default async function getBaseWebpackConfig(
new ProfilingPlugin({
tracer,
}),
!isServer &&
!dev &&
!isServer &&
useTypeScript &&
!ignoreTypeScriptErrors &&
new ForkTsCheckerWebpackPlugin(
PnpWebpackPlugin.forkTsCheckerOptions({
typescript: typeScriptPath,
async: dev,
async: false,
useTypescriptIncrementalApi: true,
checkSyntacticErrors: true,
tsconfig: tsConfigPath,
......
......@@ -10,7 +10,6 @@ import { createEntrypoints, createPagesMapping } from '../build/entries'
import { watchCompilers } from '../build/output'
import getBaseWebpackConfig from '../build/webpack-config'
import { NEXT_PROJECT_ROOT_DIST_CLIENT } from '../lib/constants'
import { fileExists } from '../lib/file-exists'
import { recursiveDelete } from '../lib/recursive-delete'
import {
BLOCKED_PAGES,
......@@ -362,19 +361,7 @@ export default class HotReloader {
}
async prepareBuildTools(multiCompiler: webpack.MultiCompiler) {
const tsConfigPath = join(this.dir, 'tsconfig.json')
const useTypeScript = await fileExists(tsConfigPath)
const ignoreTypeScriptErrors = Boolean(
this.config.experimental.reactRefresh === true ||
this.config.typescript?.ignoreDevErrors
)
watchCompilers(
multiCompiler.compilers[0],
multiCompiler.compilers[1],
useTypeScript && !ignoreTypeScriptErrors,
({ errors, warnings }) => this.send('typeChecked', { errors, warnings })
)
watchCompilers(multiCompiler.compilers[0], multiCompiler.compilers[1])
// This plugin watches for changes to _document.js and notifies the client side that it should reload the page
multiCompiler.compilers[1].hooks.done.tap(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment