Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require only build directory to be writeable for build #20977

Merged
merged 1 commit into from Jan 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 20 additions & 8 deletions packages/next/build/index.ts
Expand Up @@ -116,12 +116,6 @@ export default async function build(
): Promise<void> {
const span = tracer.startSpan('next-build')
return traceAsyncFn(span, async () => {
if (!(await isWriteable(dir))) {
throw new Error(
'> Build directory is not writeable. https://err.sh/vercel/next.js/build-dir-not-writeable'
)
}

// attempt to load global env values so they are available in next.config.js
const { loadedEnvFiles } = traceFn(tracer.startSpan('load-dotenv'), () =>
loadEnvConfig(dir, false, Log)
Expand Down Expand Up @@ -362,9 +356,27 @@ export default async function build(
i18n: config.i18n || undefined,
}))

await traceAsyncFn(tracer.startSpan('create-distdir'), () =>
promises.mkdir(distDir, { recursive: true })
const distDirCreated = await traceAsyncFn(
tracer.startSpan('create-distdir'),
async () => {
try {
await promises.mkdir(distDir, { recursive: true })
return true
} catch (err) {
if (err.code === 'EPERM') {
return false
}
throw err
}
}
)

if (!distDirCreated || !(await isWriteable(distDir))) {
throw new Error(
'> Build directory is not writeable. https://err.sh/vercel/next.js/build-dir-not-writeable'
)
}

// We need to write the manifest with rewrites before build
// so serverless can import the manifest
await traceAsyncFn(tracer.startSpan('write-routes-manifest'), () =>
Expand Down