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:
parent
d8f879402b
commit
d0dd1bc28d
9
errors/generatebuildid-not-a-string.md
Normal file
9
errors/generatebuildid-not-a-string.md
Normal 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.
|
|
@ -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([
|
||||
|
|
Loading…
Reference in a new issue