Unverified Commit 5eaaa3fb authored by Steven's avatar Steven Committed by GitHub

fix: add pretty error for `exportPathMap` with `app` dir (#47371)

The `exportPathMap` feature has been unofficially deprecated for a long time since introducing `getStaticPaths()`.

For the `app` dir, the same can be accomplished with `generateStaticParams()`.

This PR adds a pretty error when using `exportPathMap` with `app` and updates documentation to reflect the current status.


fix NEXT-836 ([link](https://linear.app/vercel/issue/NEXT-836))
parent c14c83a2
......@@ -46,7 +46,7 @@ Running `npm run build` will generate an `out` directory.
For more advanced scenarios, you can define a parameter called [`exportPathMap`](/docs/api-reference/next.config.js/exportPathMap.md) in your [`next.config.js`](/docs/api-reference/next.config.js/introduction.md) file to configure exactly which pages will be generated.
> **Warning**: Using `exportPathMap` for defining routes with any `getStaticPaths` powered page is now ignored and gets overridden. We recommend not to use them together.
> **Warning**: Using `exportPathMap` is deprecated and is overridden by `getStaticPaths` inside `pages`. We recommend not to use them together.
## Supported Features
......
......@@ -4,7 +4,7 @@ description: Customize the pages that will be exported as HTML files when using
# exportPathMap
> This feature is exclusive to `next export`. Please refer to [Static HTML export](/docs/advanced-features/static-html-export.md) if you want to learn more about it.
> This feature is exclusive to `next export` and currently **deprecated** in favor of `getStaticPaths` with `pages` or `generateStaticParams` with `app`.
<details>
<summary><b>Examples</b></summary>
......@@ -79,7 +79,7 @@ module.exports = {
next export -o outdir
```
> **Warning**: Using `exportPathMap` for defining routes with any `getStaticPaths` powered page is now ignored and gets overridden. We recommend not to use them together.
> **Warning**: Using `exportPathMap` is deprecated and is overridden by `getStaticPaths` inside `pages`. We recommend not to use them together.
## Related
......
......@@ -135,6 +135,7 @@ import { normalizePathSep } from '../shared/lib/page-path/normalize-path-sep'
import { isAppRouteRoute } from '../lib/is-app-route-route'
import { createClientRouterFilter } from '../lib/create-client-router-filter'
import { createValidFileMatcher } from '../server/lib/find-page-file'
import type { ExportOptions } from '../export'
export type SsgRoute = {
initialRevalidateSeconds: number | false
......@@ -467,6 +468,7 @@ export default async function build(
// prevent showing jest-worker internal error as it
// isn't helpful for users and clutters output
if (isError(err) && err.message === 'Call retries were exceeded') {
await telemetry.flush()
process.exit(1)
}
throw err
......@@ -478,6 +480,14 @@ export default async function build(
// directory.
if (!appDir) await startTypeChecking()
if (appDir && 'exportPathMap' in config) {
Log.error(
'The "exportPathMap" configuration cannot be used with the "app" directory. Please use generateStaticParams() instead.'
)
await telemetry.flush()
process.exit(1)
}
const buildLintEvent: EventBuildFeatureUsage = {
featureName: 'build-lint',
invocationCount: shouldLint ? 1 : 0,
......@@ -637,6 +647,7 @@ export default async function build(
for (const [pagePath, appPath] of conflictingAppPagePaths) {
Log.error(` "${pagePath}" - "${appPath}"`)
}
await telemetry.flush()
process.exit(1)
}
......@@ -2291,7 +2302,7 @@ export default async function build(
)
const exportApp: typeof import('../export').default =
require('../export').default
const exportOptions = {
const exportOptions: ExportOptions = {
silent: false,
buildExport: true,
debugOutput,
......@@ -2309,7 +2320,7 @@ export default async function build(
: undefined,
appPaths,
}
const exportConfig: any = {
const exportConfig: NextConfigComplete = {
...config,
initialPageRevalidationMap: {},
initialPageMetaMap: {},
......
......@@ -143,7 +143,7 @@ const createProgress = (total: number, label: string) => {
}
}
interface ExportOptions {
export interface ExportOptions {
outdir: string
silent?: boolean
threads?: number
......@@ -369,11 +369,6 @@ export default async function exportApp(
// Get the exportPathMap from the config file
if (typeof nextConfig.exportPathMap !== 'function') {
if (!options.silent) {
Log.info(
`No "exportPathMap" found in "${nextConfig.configFile}". Generating map from "./pages"`
)
}
nextConfig.exportPathMap = async (defaultMap) => {
return defaultMap
}
......
......@@ -235,4 +235,25 @@ describe('app dir with output export', () => {
'export const dynamic = "force-dynamic" on page "/api/json" cannot be used with "output: export".'
)
})
it('should throw when exportPathMap configured', async () => {
nextConfig.replace(
'trailingSlash: true,',
`trailingSlash: true,
exportPathMap: async function (map) {
return map
},`
)
await fs.remove(distDir)
await fs.remove(exportDir)
let result = { code: 0, stderr: '' }
try {
result = await nextBuild(appDir, [], { stderr: true })
} finally {
nextConfig.restore()
}
expect(result.code).toBe(1)
expect(result.stderr).toContain(
'The "exportPathMap" configuration cannot be used with the "app" directory. Please use generateStaticParams() instead.'
)
})
})
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