Skip to content

Commit dadc7fa

Browse files
committed
fix: use default publish dir
1 parent 13d3a7e commit dadc7fa

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

helpers/checkNxConfig.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { existsSync } = require('fs')
22
const { EOL } = require('os')
33
const path = require('path')
44

5-
const checkNxConfig = ({ netlifyConfig, nextConfig, failBuild, constants: { PUBLISH_DIR } }) => {
5+
const checkNxConfig = ({ netlifyConfig, nextConfig, failBuild, constants: { PUBLISH_DIR = 'out' } }) => {
66
const errors = []
77
if (nextConfig.distDir === '.next') {
88
errors.push(
@@ -15,8 +15,9 @@ const checkNxConfig = ({ netlifyConfig, nextConfig, failBuild, constants: { PUBL
1515
"Please set the 'publish' value in your Netlify build config to a folder inside your app directory. e.g. 'apps/myapp/out'",
1616
)
1717
}
18+
1819
// Look for the config file as a sibling of the publish dir
19-
const expectedConfigFile = path.resolve(netlifyConfig.build.publish, '..', 'next.config.js')
20+
const expectedConfigFile = path.resolve(netlifyConfig.build.publish || PUBLISH_DIR, '..', 'next.config.js')
2021

2122
if (expectedConfigFile !== nextConfig.configFile) {
2223
const confName = path.relative(process.cwd(), nextConfig.configFile)

helpers/getNextRoot.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ const path = require('path')
77
*/
88
const getNextRoot = ({ netlifyConfig }) => {
99
let nextRoot = process.cwd()
10-
if (!existsSync(path.join(nextRoot, 'next.config.js')) && netlifyConfig.build.publish) {
10+
if (
11+
!existsSync(path.join(nextRoot, 'next.config.js')) &&
12+
netlifyConfig.build.publish &&
13+
netlifyConfig.build.publish !== nextRoot
14+
) {
1115
nextRoot = path.dirname(netlifyConfig.build.publish)
1216
}
1317
return nextRoot

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { readdirSync } = require('fs')
12
const path = require('path')
23

34
const makeDir = require('make-dir')
@@ -60,7 +61,7 @@ module.exports = {
6061
async onBuild({
6162
netlifyConfig,
6263
packageJson,
63-
constants: { PUBLISH_DIR, FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC },
64+
constants: { PUBLISH_DIR = DEFAULT_PUBLISH_DIR, FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC },
6465
utils,
6566
}) {
6667
const { failBuild } = utils.build
@@ -74,10 +75,9 @@ module.exports = {
7475
console.log(`** Running Next on Netlify package **`)
7576

7677
await makeDir(PUBLISH_DIR)
77-
7878
await nextOnNetlify({
7979
functionsDir: path.resolve(FUNCTIONS_SRC),
80-
publishDir: netlifyConfig.build.publish,
80+
publishDir: netlifyConfig.build.publish || PUBLISH_DIR,
8181
nextRoot,
8282
})
8383
},
@@ -96,3 +96,4 @@ module.exports = {
9696

9797
const DEFAULT_FUNCTIONS_SRC = 'netlify/functions'
9898
const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/'
99+
const DEFAULT_PUBLISH_DIR = 'out'

src/lib/steps/copyNextAssets.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { join } = require('path')
1+
const { join, resolve } = require('path')
22

33
const { copySync, existsSync } = require('fs-extra')
44

@@ -16,7 +16,9 @@ const copyNextAssets = async (publishPath) => {
1616
const staticAssetsPath = join(nextDistDir, 'static')
1717
if (!existsSync(staticAssetsPath)) {
1818
throw new Error(
19-
`No static assets found in your distDir (missing /static in ${nextDistDir}). Please check your project configuration. Your next.config.js must be one of \`serverless\` or \`experimental-serverless-trace\`. Your build command should include \`next build\`.`,
19+
`No static assets found in your distDir (missing /static in ${resolve(
20+
nextDistDir,
21+
)}). Please check your project configuration. Your next.config.js must be one of \`serverless\` or \`experimental-serverless-trace\`. Your build command should include \`next build\`.`,
2022
)
2123
}
2224
logTitle('💼 Copying static NextJS assets to', publishPath)

0 commit comments

Comments
 (0)