1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Trim buildId returned from generateBuildId (#5634)

* Trim buildId returned from generateBuildId

* Pass dir to function
This commit is contained in:
Tim Neutkens 2018-11-12 15:57:48 +01:00 committed by GitHub
parent d8f879402b
commit d0dd1bc28d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 10 deletions

View file

@ -0,0 +1,9 @@
# generateBuildId did not return a string
#### Why This Error Occurred
The most common cause for this issue is a custom `next.config.js` with the `generateBuildId` method defined, but it does not return a string.
#### Possible Ways to Fix It
Always return a string from generateBuildId.

View file

@ -10,22 +10,34 @@ import getBaseWebpackConfig from './webpack'
const access = promisify(fs.access)
const writeFile = promisify(fs.writeFile)
export default async function build (dir, conf = null) {
const config = loadConfig(PHASE_PRODUCTION_BUILD, dir, conf)
const distDir = join(dir, config.distDir)
let buildId = await config.generateBuildId() // defaults to a uuid
if (buildId == null) {
// nanoid is a small url-safe uuid generator
buildId = nanoid()
async function generateBuildId (generate, fallback) {
let buildId = await generate()
// If there's no buildId defined we'll fall back
if (buildId === null) {
buildId = fallback()
}
if (typeof buildId !== 'string') {
throw new Error('generateBuildId did not return a string. https://err.sh/zeit/next.js/generatebuildid-not-a-string')
}
return buildId.trim()
}
async function ensureProjectDirectoryIsWriteAble (dir) {
try {
await access(dir, (fs.constants || fs).W_OK)
} catch (err) {
console.error(`> Failed, build directory is not writeable. https://err.sh/zeit/next.js/build-dir-not-writeable`)
throw err
throw new Error('Build directory is not writeable. https://err.sh/zeit/next.js/build-dir-not-writeable')
}
}
export default async function build (dir, conf = null) {
const config = loadConfig(PHASE_PRODUCTION_BUILD, dir, conf)
const distDir = join(dir, config.distDir)
const buildId = await generateBuildId(config.generateBuildId, nanoid)
await ensureProjectDirectoryIsWriteAble(dir)
try {
const configs = await Promise.all([