It appears that the CreatePages function is not being called during the build step. With Ts #37612
-
The CreatePages function defined in gatsby-node.ts is not executed during the build step. In fact, it is not called even when I set a breakpoint in debug mode, and I cannot even step in. How can I get it to work? I would appreciate your wisdom. I present my gatsby-node.ts, but it is not being called, so I don't think the content of the function is the problem. By the way, it was working when the extension was js and the syntax was CommonJS. import cheerio from "cheerio";
import hljs from "highlight.js/lib/core";
import { GatsbyNode } from "gatsby";
import { resolve } from "path";
const createPages: GatsbyNode["createPages"] = async ({
graphql,
actions: { createPage },
}) => {
const result = await graphql<Queries.CreatePagesQuery>(
`
query CreatePages {
site {
siteMetadata {
title
author
}
}
allMicrocmsBlog(sort: { publishedAt: DESC }) {
edges {
node {
blogId
title
publishedAt
id
content
eyecatch {
url
}
description
}
previous {
blogId
title
}
next {
blogId
title
}
}
}
}
`
);
if (result.errors) {
throw result.errors;
}
result.data?.allMicrocmsBlog.edges.forEach((post, _) => {
const $ = cheerio.load(post.node.content || "");
$("pre code").each((_, elm) => {
const result = hljs.highlightAuto($(elm).text());
$(elm).html(result.value);
$(elm).addClass("hljs");
});
createPage({
path: `/articles/${post.node.blogId}`,
component: resolve("./src/components/template.tsx"),
context: {
id: post.node.id,
siteMetadata: result.data?.site?.siteMetadata,
microcmsBlog: post.node,
content: $.html(),
previous: post.next,
next: post.previous,
},
});
});
};
export { createPages };
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The code looks fine. I tried changing npx gatsby new gatsby-starter-default https://github.com/gatsbyjs/gatsby-starter-default
cd gatsby-starter-default mv gatsby-node.js gatsby-node.ts Edited from /**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/
*/
/**
* @type {import('gatsby').GatsbyNode['createPages']}
*/
exports.createPages = async ({ actions }) => {
const { createPage } = actions
createPage({
path: "/using-dsg",
component: require.resolve("./src/templates/using-dsg.js"),
context: {},
defer: true,
})
} to /**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/
*/
import type { GatsbyNode } from "gatsby"
import { resolve } from "path"
/**
* @type {import('gatsby').GatsbyNode['createPages']}
*/
const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
const { createPage } = actions
createPage({
path: "/using-dsg",
component: resolve("./src/templates/using-dsg.js"),
context: {},
defer: true,
})
}
export {
createPages
} Then I built and ran npm run clean
npm run build The page
Does the problem stay after you run |
Beta Was this translation helpful? Give feedback.
The code looks fine.
I tried changing
gatsby-node.js
togatsby-node.ts
that usescreatePages()
to reproduce the problem but it works.npx gatsby new gatsby-starter-default https://github.com/gatsbyjs/gatsby-starter-default cd gatsby-starter-default
Edited
gatsgy-node.ts
as follows:from