Unverified Commit c5bccf4d authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

fix(next/dev): bubble up unhandled exception from --turbo (#42594)

<!--
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 that you're making:
-->

This PR fixes `--turbo` can shallow some of unhandled exception, trying
to catch and proceed as much as it can.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 6f136f6a
...@@ -165,6 +165,8 @@ const nextDev: cliCommand = (argv) => { ...@@ -165,6 +165,8 @@ const nextDev: cliCommand = (argv) => {
const { setGlobal } = require('../trace') as typeof import('../trace') const { setGlobal } = require('../trace') as typeof import('../trace')
const { Telemetry } = const { Telemetry } =
require('../telemetry/storage') as typeof import('../telemetry/storage') require('../telemetry/storage') as typeof import('../telemetry/storage')
const findUp =
require('next/dist/compiled/find-up') as typeof import('next/dist/compiled/find-up')
// To regenerate the TURBOPACK gradient require('gradient-string')('blue', 'red')('>>> TURBOPACK') // To regenerate the TURBOPACK gradient require('gradient-string')('blue', 'red')('>>> TURBOPACK')
const isTTY = process.stdout.isTTY const isTTY = process.stdout.isTTY
...@@ -182,7 +184,13 @@ const nextDev: cliCommand = (argv) => { ...@@ -182,7 +184,13 @@ const nextDev: cliCommand = (argv) => {
let babelrc = await getBabelConfigFile(dir) let babelrc = await getBabelConfigFile(dir)
if (babelrc) babelrc = path.basename(babelrc) if (babelrc) babelrc = path.basename(babelrc)
const rawNextConfig = interopDefault( let hasNonDefaultConfig
let postcssFile
let tailwindFile
let rawNextConfig: NextConfig
try {
rawNextConfig = interopDefault(
await loadConfig(PHASE_DEVELOPMENT_SERVER, dir, undefined, true) await loadConfig(PHASE_DEVELOPMENT_SERVER, dir, undefined, true)
) as NextConfig ) as NextConfig
...@@ -191,6 +199,7 @@ const nextDev: cliCommand = (argv) => { ...@@ -191,6 +199,7 @@ const nextDev: cliCommand = (argv) => {
parentUserConfig: any, parentUserConfig: any,
parentDefaultConfig: any parentDefaultConfig: any
): boolean => { ): boolean => {
try {
// these should not error // these should not error
if ( if (
configKey === 'serverComponentsExternalPackages' || configKey === 'serverComponentsExternalPackages' ||
...@@ -202,8 +211,8 @@ const nextDev: cliCommand = (argv) => { ...@@ -202,8 +211,8 @@ const nextDev: cliCommand = (argv) => {
) { ) {
return false return false
} }
let userValue = parentUserConfig[configKey] let userValue = parentUserConfig?.[configKey]
let defaultValue = parentDefaultConfig[configKey] let defaultValue = parentDefaultConfig?.[configKey]
if (typeof defaultValue !== 'object') { if (typeof defaultValue !== 'object') {
return defaultValue !== userValue return defaultValue !== userValue
...@@ -211,14 +220,19 @@ const nextDev: cliCommand = (argv) => { ...@@ -211,14 +220,19 @@ const nextDev: cliCommand = (argv) => {
return Object.keys(userValue || {}).some((key: string) => { return Object.keys(userValue || {}).some((key: string) => {
return checkUnsupportedCustomConfig(key, userValue, defaultValue) return checkUnsupportedCustomConfig(key, userValue, defaultValue)
}) })
} catch (e) {
console.error(
`Unexpected error occurred while checking ${configKey}`,
e
)
return false
}
} }
const hasNonDefaultConfig = Object.keys(rawNextConfig).some((key) => hasNonDefaultConfig = Object.keys(rawNextConfig).some((key) =>
checkUnsupportedCustomConfig(key, rawNextConfig, defaultConfig) checkUnsupportedCustomConfig(key, rawNextConfig, defaultConfig)
) )
const findUp =
require('next/dist/compiled/find-up') as typeof import('next/dist/compiled/find-up')
const packagePath = findUp.sync('package.json', { cwd: dir }) const packagePath = findUp.sync('package.json', { cwd: dir })
let hasSideCar = false let hasSideCar = false
...@@ -227,14 +241,18 @@ const nextDev: cliCommand = (argv) => { ...@@ -227,14 +241,18 @@ const nextDev: cliCommand = (argv) => {
hasSideCar = Object.values( hasSideCar = Object.values(
(pkgData.scripts || {}) as Record<string, string> (pkgData.scripts || {}) as Record<string, string>
).some( ).some(
(script) => script.includes('tailwind') || script.includes('postcss') (script) =>
script.includes('tailwind') || script.includes('postcss')
) )
} }
let postcssFile = !hasSideCar && (await findConfigPath(dir, 'postcss')) postcssFile = !hasSideCar && (await findConfigPath(dir, 'postcss'))
let tailwindFile = !hasSideCar && (await findConfigPath(dir, 'tailwind')) tailwindFile = !hasSideCar && (await findConfigPath(dir, 'tailwind'))
if (postcssFile) postcssFile = path.basename(postcssFile) if (postcssFile) postcssFile = path.basename(postcssFile)
if (tailwindFile) tailwindFile = path.basename(tailwindFile) if (tailwindFile) tailwindFile = path.basename(tailwindFile)
} catch (e) {
console.error('Unexpected error occurred while checking config', e)
}
const hasWarningOrError = const hasWarningOrError =
tailwindFile || postcssFile || babelrc || hasNonDefaultConfig tailwindFile || postcssFile || babelrc || hasNonDefaultConfig
...@@ -381,6 +399,8 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit ...@@ -381,6 +399,8 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit
console.error(err) console.error(err)
} }
) )
}).catch((err) => {
console.error(err)
}) })
} else { } else {
startServer(devServerOptions) startServer(devServerOptions)
......
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