Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

throw error if .next/static cannot be found #148

Merged
merged 2 commits into from
Jan 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/steps/copyNextAssets.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const { join } = require("path");
const { copySync } = require("fs-extra");
const { copySync, existsSync } = require("fs-extra");
const { logTitle } = require("../helpers/logger");
const { NEXT_DIST_DIR } = require("../config");

// Copy the NextJS' static assets from NextJS distDir to Netlify publish folder.
// These need to be available for NextJS to work.
const copyNextAssets = (publishPath) => {
const staticAssetsPath = join(NEXT_DIST_DIR, "static");
if (!existsSync(staticAssetsPath)) {
throw new Error("No static assets found in .next dist (aka no /.next/static). 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`.");
}
logTitle("💼 Copying static NextJS assets to", publishPath);
copySync(
join(NEXT_DIST_DIR, "static"),
join(publishPath, "_next", "static"),
{
overwrite: false,
errorOnExist: true,
}
);
copySync(staticAssetsPath, join(publishPath, "_next", "static"), {
overwrite: false,
errorOnExist: true,
});
};

module.exports = copyNextAssets;