From 9e87596bd6e7a472eea1979e14219ec4bf9267a6 Mon Sep 17 00:00:00 2001 From: Darsh Patel Date: Mon, 10 May 2021 14:09:18 +0530 Subject: [PATCH] Fix: Non-writable pages/_app breaks build (#24849) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../webpack/loaders/next-serverless-loader/page-handler.ts | 2 +- packages/next/next-server/server/next-server.ts | 2 +- packages/next/server/lib/find-page-file.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/next/build/webpack/loaders/next-serverless-loader/page-handler.ts b/packages/next/build/webpack/loaders/next-serverless-loader/page-handler.ts index ccbfe30d15050..35682cfc37225 100644 --- a/packages/next/build/webpack/loaders/next-serverless-loader/page-handler.ts +++ b/packages/next/build/webpack/loaders/next-serverless-loader/page-handler.ts @@ -412,7 +412,7 @@ export function getPageHandler(ctx: ServerlessHandlerCtx) { if (err.code === 'ENOENT') { res.statusCode = 404 - } else if (err.code === 'DECODE_FAILED') { + } else if (err.code === 'DECODE_FAILED' || err.code === 'ENAMETOOLONG') { // TODO: better error? res.statusCode = 400 } else { diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index abad677883798..0b367f43a1a4e 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -1255,7 +1255,7 @@ export default class Server { return } } catch (err) { - if (err.code === 'DECODE_FAILED') { + if (err.code === 'DECODE_FAILED' || err.code === 'ENAMETOOLONG') { res.statusCode = 400 return this.renderError(null, req, res, '/_error', {}) } diff --git a/packages/next/server/lib/find-page-file.ts b/packages/next/server/lib/find-page-file.ts index 149a93f8893cb..08da65906416e 100644 --- a/packages/next/server/lib/find-page-file.ts +++ b/packages/next/server/lib/find-page-file.ts @@ -1,9 +1,9 @@ import { join, sep as pathSeparator, normalize } from 'path' import chalk from 'chalk' -import { isWriteable } from '../../build/is-writeable' import { warn } from '../../build/output/log' import { promises } from 'fs' import { denormalizePagePath } from '../../next-server/server/normalize-page-path' +import { fileExists } from '../../lib/file-exists' async function isTrueCasePagePath(pagePath: string, pagesDir: string) { const pageSegments = normalize(pagePath).split(pathSeparator).filter(Boolean) @@ -31,14 +31,14 @@ export async function findPageFile( const relativePagePath = `${page}.${extension}` const pagePath = join(rootDir, relativePagePath) - if (await isWriteable(pagePath)) { + if (await fileExists(pagePath)) { foundPagePaths.push(relativePagePath) } } const relativePagePathWithIndex = join(page, `index.${extension}`) const pagePathWithIndex = join(rootDir, relativePagePathWithIndex) - if (await isWriteable(pagePathWithIndex)) { + if (await fileExists(pagePathWithIndex)) { foundPagePaths.push(relativePagePathWithIndex) } }