Skip to content

Commit

Permalink
Ensure configuration is checked for Turbopack build (#64247)
Browse files Browse the repository at this point in the history
## What?

Currently any configuration issue like including `.babelrc` was not
highlighted during Turbopack build. This PR solves that issue as well as
ensuring the warnings are not double-logged because of a change that was
supposed to be development-only.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-3049
  • Loading branch information
timneutkens authored Apr 10, 2024
1 parent e1e3332 commit 4c128a5
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 45 deletions.
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

0 comments on commit 4c128a5

Please sign in to comment.