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) => {
const { setGlobal } = require('../trace') as typeof import('../trace')
const { Telemetry } =
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')
const isTTY = process.stdout.isTTY
......@@ -182,59 +184,75 @@ const nextDev: cliCommand = (argv) => {
let babelrc = await getBabelConfigFile(dir)
if (babelrc) babelrc = path.basename(babelrc)
const rawNextConfig = interopDefault(
await loadConfig(PHASE_DEVELOPMENT_SERVER, dir, undefined, true)
) as NextConfig
const checkUnsupportedCustomConfig = (
configKey = '',
parentUserConfig: any,
parentDefaultConfig: any
): boolean => {
// these should not error
if (
configKey === 'serverComponentsExternalPackages' ||
configKey === 'appDir' ||
configKey === 'transpilePackages' ||
configKey === 'reactStrictMode' ||
configKey === 'swcMinify' ||
configKey === 'configFileName'
) {
return false
}
let userValue = parentUserConfig[configKey]
let defaultValue = parentDefaultConfig[configKey]
let hasNonDefaultConfig
let postcssFile
let tailwindFile
let rawNextConfig: NextConfig
try {
rawNextConfig = interopDefault(
await loadConfig(PHASE_DEVELOPMENT_SERVER, dir, undefined, true)
) as NextConfig
const checkUnsupportedCustomConfig = (
configKey = '',
parentUserConfig: any,
parentDefaultConfig: any
): boolean => {
try {
// these should not error
if (
configKey === 'serverComponentsExternalPackages' ||
configKey === 'appDir' ||
configKey === 'transpilePackages' ||
configKey === 'reactStrictMode' ||
configKey === 'swcMinify' ||
configKey === 'configFileName'
) {
return false
}
let userValue = parentUserConfig?.[configKey]
let defaultValue = parentDefaultConfig?.[configKey]
if (typeof defaultValue !== 'object') {
return defaultValue !== userValue
if (typeof defaultValue !== 'object') {
return defaultValue !== userValue
}
return Object.keys(userValue || {}).some((key: string) => {
return checkUnsupportedCustomConfig(key, userValue, defaultValue)
})
} catch (e) {
console.error(
`Unexpected error occurred while checking ${configKey}`,
e
)
return false
}
}
return Object.keys(userValue || {}).some((key: string) => {
return checkUnsupportedCustomConfig(key, userValue, defaultValue)
})
}
const hasNonDefaultConfig = Object.keys(rawNextConfig).some((key) =>
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 })
let hasSideCar = false
if (packagePath) {
const pkgData = require(packagePath)
hasSideCar = Object.values(
(pkgData.scripts || {}) as Record<string, string>
).some(
(script) => script.includes('tailwind') || script.includes('postcss')
hasNonDefaultConfig = Object.keys(rawNextConfig).some((key) =>
checkUnsupportedCustomConfig(key, rawNextConfig, defaultConfig)
)
}
let postcssFile = !hasSideCar && (await findConfigPath(dir, 'postcss'))
let tailwindFile = !hasSideCar && (await findConfigPath(dir, 'tailwind'))
if (postcssFile) postcssFile = path.basename(postcssFile)
if (tailwindFile) tailwindFile = path.basename(tailwindFile)
const packagePath = findUp.sync('package.json', { cwd: dir })
let hasSideCar = false
if (packagePath) {
const pkgData = require(packagePath)
hasSideCar = Object.values(
(pkgData.scripts || {}) as Record<string, string>
).some(
(script) =>
script.includes('tailwind') || script.includes('postcss')
)
}
postcssFile = !hasSideCar && (await findConfigPath(dir, 'postcss'))
tailwindFile = !hasSideCar && (await findConfigPath(dir, 'tailwind'))
if (postcssFile) postcssFile = path.basename(postcssFile)
if (tailwindFile) tailwindFile = path.basename(tailwindFile)
} catch (e) {
console.error('Unexpected error occurred while checking config', e)
}
const hasWarningOrError =
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
console.error(err)
}
)
}).catch((err) => {
console.error(err)
})
} else {
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