Skip to content

Commit ea534d8

Browse files
author
Vivek Vishal
authored
Merge pull request #6512 from layer5io/vishalvivekm-patch-3
fix: skip page creation for missing component files
2 parents c3cd22f + 2e1005d commit ea534d8

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

gatsby-node.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
const path = require("path");
9+
const fs = require("fs");
910
const slugify = require("./src/utils/slugify");
1011
const { paginate } = require("gatsby-awesome-pagination");
1112
const { createFilePath } = require("gatsby-source-filesystem");
@@ -797,15 +798,19 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
797798

798799
components.forEach((name) => {
799800
pageTypes.forEach(({ suffix, file }) => {
800-
const path = `/projects/sistent/components/${name}${suffix}`;
801+
const pagePath = `/projects/sistent/components/${name}${suffix}`;
801802
const componentPath = `./src/sections/Projects/Sistent/components/${name}/${file}`;
802-
try {
803-
createPage({
804-
path,
805-
component: require.resolve(componentPath),
806-
});
807-
} catch (error) {
808-
console.error(`Error creating page for ${path}:`, error);
803+
if (fs.existsSync(path.resolve(componentPath))) {
804+
try {
805+
createPage({
806+
path: pagePath,
807+
component: require.resolve(componentPath),
808+
});
809+
} catch (error) {
810+
console.error(`Error creating page for "${pagePath}":`, error);
811+
}
812+
} else {
813+
console.info(`Skipping creating page "${pagePath}" - file not found: "${componentPath}"`);
809814
}
810815
});
811816
});
@@ -1101,7 +1106,7 @@ exports.createSchemaCustomization = ({ actions }) => {
11011106
createTypes(typeDefs);
11021107
};
11031108

1104-
const fs = require("fs");
1109+
11051110

11061111
exports.onPostBuild = async ({ graphql, reporter }) => {
11071112
const result = await graphql(`

0 commit comments

Comments
 (0)