Gatsby Node createPages is not working with Typescript #35851
-
Preliminary Checks
DescriptionI just create a Gatsby project, which I have cloned from this starter-default. I want to add Typescript to the project just for the sake of VSCode's syntax highlighting. So I found that Gatsby supports Typescript natively. Anyway, I followed this article to add Typescript to Gatsby config files. Then I encounter an error with
Here is the import type { GatsbyNode } from "gatsby";
export const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
const { createPage } = actions;
createPage({
path: "/using-dsg",
component: require.resolve("./src/templates/using-dsg.tsx"),
context: {},
defer: true,
});
}; The code is completely the same as in the starter. I just migrate it to Typescript. Reproduction LinkI don't have any reproduction since this is just my first initialization with Gatsby and Typescript Steps to ReproduceThe error doesn't happen when I convert it back to JS version. And Gatsby does provide a suggestion for syntax highlighting while it's still in Javascript. Expected ResultTypescript version should work like Javascript version ( Actual ResultSee the error above Environment❯ npx gatsby info --clipboard
System:
OS: Linux 5.4 Ubuntu 18.04.6 LTS (Bionic Beaver)
CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
Shell: 5.4.2 - /usr/bin/zsh
Binaries:
Node: 16.1.0 - ~/.nvm/versions/node/v16.1.0/bin/node
Yarn: 1.22.17 - ~/.yarn/bin/yarn
npm: 8.3.0 - ~/.nvm/versions/node/v16.1.0/bin/npm
Languages:
Python: 2.7.17 - /usr/bin/python
npmPackages:
gatsby: ^4.15.2 => 4.15.2
gatsby-plugin-gatsby-cloud: ^4.15.0 => 4.15.0
gatsby-plugin-image: ^2.15.1 => 2.15.1
gatsby-plugin-manifest: ^4.15.1 => 4.15.1
gatsby-plugin-netlify: ^5.0.0 => 5.0.0
gatsby-plugin-offline: ^5.15.1 => 5.15.1
gatsby-plugin-react-helmet: ^5.15.0 => 5.15.0
gatsby-plugin-sharp: ^4.15.1 => 4.15.1
gatsby-source-filesystem: ^4.15.0 => 4.15.0
gatsby-transformer-sharp: ^4.15.1 => 4.15.1
npmGlobalPackages:
gatsby-cli: 4.15.1
gatsby: 4.15.2 Config FlagsNone |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi! You'll need to change your |
Beta Was this translation helpful? Give feedback.
Hi!
You'll need to change your
require.resolve
topath.resolve
, see: https://www.gatsbyjs.com/docs/how-to/custom-configuration/typescript/#requireresolve