diff --git a/packages/gatsby/src/internal-plugins/dev-404-page/gatsby-node.js b/packages/gatsby/src/internal-plugins/dev-404-page/gatsby-node.js index 8540086d2d3ca..7a381d26b228d 100644 --- a/packages/gatsby/src/internal-plugins/dev-404-page/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/dev-404-page/gatsby-node.js @@ -1,6 +1,8 @@ const path = require(`path`) const fs = require(`fs-extra`) +let createdPage = false + exports.createPages = async ({ store, boundActionCreators }) => { if (process.env.NODE_ENV !== `production`) { const { program } = store.getState() @@ -8,11 +10,15 @@ exports.createPages = async ({ store, boundActionCreators }) => { const currentPath = path.join(__dirname, `./raw_dev-404-page.js`) const newPath = path.join(program.directory, `.cache`, `dev-404-page.js`) - await fs.copy(currentPath, newPath) + if (!createdPage) { + createdPage = true + + await fs.copy(currentPath, newPath) - createPage({ - component: newPath, - path: `/dev-404-page/`, - }) + createPage({ + component: newPath, + path: `/dev-404-page/`, + }) + } } }