Gatsby Plugin Netlify CMS does not work with TypeScript?

444 views Asked by At

I am trying to integrate gatsby-plugin-netlify-cms with Gatsby typescript and everytime I try to build the website, I get the following error message.

"You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file."

My gatsby-config.js file is written as follow,

module.exports = {
  /* Your site config here */
  plugins: [
    `gatsby-plugin-styled-components`,
    {
      resolve: `gatsby-plugin-netlify-cms`,
      options: {
        modulePath: `${__dirname}/src/cms/cms.ts`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `markdown-pages`,
        path: `${__dirname}/src/pages`,
      },
    },
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-images`,
            options: {
              maxWidth: 512,
            },
          },
        ],
      },
    },
    `gatsby-plugin-netlify`,
  ],
};

I was able to get Typescript to work for the rest of my project and it only started to fail when I tried to modify preview templates. Specifically, everything broke when I wrote the following code gatsby-plugin-netlify-cms.

options: {
    modulePath: `${__dirname}/src/cms/cms.ts`,
},

Why am I getting the error message?

1

There are 1 answers

0
IAmWorking On

Closing this for anyone else who encounters this error. I added the following line of code to the gatsby-config.js file.

plugins: [
  {
    resolve: 'gatsby-plugin-typescript',
    options: {
      isTSX: true,
      allExtensions: true,
    },
  },
]

This fixed the error for me.