Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure configuration is checked for Turbopack build #64247

Merged
35 changes: 32 additions & 3 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import type {
import { nonNullable } from '../lib/non-nullable'
import { recursiveDelete } from '../lib/recursive-delete'
import { verifyPartytownSetup } from '../lib/verify-partytown-setup'
import { validateTurboNextConfig } from '../lib/turbopack-warning'
import {
BUILD_ID_FILE,
BUILD_MANIFEST,
Expand Down Expand Up @@ -176,7 +177,7 @@ import {
handleRouteType,
handlePagesErrorRoute,
formatIssue,
printNonFatalIssue,
isRelevantWarning,
} from '../server/dev/turbopack-utils'
import { TurbopackManifestLoader } from '../server/dev/turbopack/manifest-loader'
import type { Entrypoints } from '../server/dev/turbopack/types'
Expand Down Expand Up @@ -1346,6 +1347,11 @@ export default async function build(
throw new Error("next build doesn't support turbopack yet")
}

await validateTurboNextConfig({
dir,
isDev: false,
})

const startTime = process.hrtime()
const bindings = await loadBindings(config?.experimental?.useWasmBinary)
const dev = false
Expand Down Expand Up @@ -1448,6 +1454,7 @@ export default async function build(
manifestLoader,
nextConfig: config,
rewrites: emptyRewritesObjToBeImplemented,
logErrors: false,
})

const progress = createProgress(
Expand Down Expand Up @@ -1482,6 +1489,7 @@ export default async function build(
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,
logErrors: false,
})
)
}
Expand All @@ -1497,6 +1505,7 @@ export default async function build(
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,
logErrors: false,
})
)
}
Expand All @@ -1507,6 +1516,7 @@ export default async function build(
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,
logErrors: false,
})
)
await Promise.all(promises)
Expand All @@ -1520,6 +1530,10 @@ export default async function build(
page: string
message: string
}[] = []
const warnings: {
page: string
message: string
}[] = []
for (const [page, entryIssues] of currentEntryIssues) {
for (const issue of entryIssues.values()) {
if (issue.severity !== 'warning') {
Expand All @@ -1528,14 +1542,29 @@ export default async function build(
message: formatIssue(issue),
})
} else {
printNonFatalIssue(issue)
if (isRelevantWarning(issue)) {
warnings.push({
page,
message: formatIssue(issue),
})
}
}
}
}

if (warnings.length > 0) {
Log.warn(
`Turbopack build collected ${warnings.length} warnings:\n${warnings
.map((e) => {
return 'Page: ' + e.page + '\n' + e.message
})
.join('\n')}`
)
}

if (errors.length > 0) {
throw new Error(
`Turbopack build failed with ${errors.length} issues:\n${errors
`Turbopack build failed with ${errors.length} errors:\n${errors
.map((e) => {
return 'Page: ' + e.page + '\n' + e.message
})
Expand Down
32 changes: 14 additions & 18 deletions packages/next/src/lib/turbopack-warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { NextConfig } from '../server/config-shared'
import path from 'path'
import loadConfig from '../server/config'
import * as Log from '../build/output/log'
import { PHASE_DEVELOPMENT_SERVER } from '../shared/lib/constants'
import {
PHASE_DEVELOPMENT_SERVER,
PHASE_PRODUCTION_BUILD,
} from '../shared/lib/constants'

const unsupportedTurbopackNextConfigOptions = [
// is this supported?
Expand Down Expand Up @@ -48,21 +51,13 @@ const unsupportedTurbopackNextConfigOptions = [
]

// The following will need to be supported by `next build --turbo`
const prodSpecificTurboNextConfigOptions = [
'eslint',
'typescript',
const unsupportedProductionSpecificTurbopackNextConfigOptions = [
'outputFileTracing',
'generateBuildId',
'compress',
'productionBrowserSourceMaps',
'optimizeFonts',
'poweredByHeader',
'staticPageGenerationTimeout',
// TODO: Support disabling sourcemaps, currently they're always enabled.
// 'productionBrowserSourceMaps',
'reactProductionProfiling',
'cleanDistDir',
'experimental.turbotrace',
'experimental.outputFileTracingRoot',
'experimental.outputFileTracingExcludes',
'experimental.outputFileTracingIgnores',
'experimental.outputFileTracingIncludes',
]
Expand All @@ -72,10 +67,7 @@ export async function validateTurboNextConfig({
dir,
isDev,
}: {
allowRetry?: boolean
dir: string
port: number
hostname?: string
isDev?: boolean
}) {
const { getPkgManager } =
Expand All @@ -99,15 +91,16 @@ export async function validateTurboNextConfig({
let unsupportedConfig: string[] = []
let rawNextConfig: NextConfig = {}

const phase = isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD
try {
rawNextConfig = interopDefault(
await loadConfig(PHASE_DEVELOPMENT_SERVER, dir, {
await loadConfig(phase, dir, {
rawConfig: true,
})
) as NextConfig

if (typeof rawNextConfig === 'function') {
rawNextConfig = (rawNextConfig as any)(PHASE_DEVELOPMENT_SERVER, {
rawNextConfig = (rawNextConfig as any)(phase, {
defaultConfig,
})
}
Expand Down Expand Up @@ -150,7 +143,10 @@ export async function validateTurboNextConfig({

let unsupportedKeys = isDev
? unsupportedTurbopackNextConfigOptions
: prodSpecificTurboNextConfigOptions
: [
...unsupportedTurbopackNextConfigOptions,
...unsupportedProductionSpecificTurbopackNextConfigOptions,
]

for (const key of customKeys) {
if (key.startsWith('webpack') && rawNextConfig.webpack) {
Expand Down
7 changes: 5 additions & 2 deletions packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export async function createHotReloaderTurbopack(
const changed = await changedPromise

for await (const change of changed) {
processIssues(currentEntryIssues, key, change)
processIssues(currentEntryIssues, key, change, false, true)
const payload = await makePayload(change)
if (payload) {
sendHmr(key, payload)
Expand Down Expand Up @@ -401,7 +401,7 @@ export async function createHotReloaderTurbopack(
await subscription.next()

for await (const data of subscription) {
processIssues(state.clientIssues, key, data)
processIssues(state.clientIssues, key, data, false, true)
if (data.type !== 'issues') {
sendTurbopackMessage(data)
}
Expand Down Expand Up @@ -453,6 +453,7 @@ export async function createHotReloaderTurbopack(
manifestLoader,
nextConfig: opts.nextConfig,
rewrites: opts.fsChecker.rewrites,
logErrors: true,

dev: {
assetMapper,
Expand Down Expand Up @@ -778,6 +779,7 @@ export async function createHotReloaderTurbopack(
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: opts.fsChecker.rewrites,
logErrors: true,

hooks: {
subscribeToChanges,
Expand Down Expand Up @@ -830,6 +832,7 @@ export async function createHotReloaderTurbopack(
manifestLoader,
readyIds,
rewrites: opts.fsChecker.rewrites,
logErrors: true,

hooks: {
subscribeToChanges,
Expand Down
Loading