CssDependency Error during Gatsby site build

Hi there,

I’ve had this issue crop up a few times, last time I tried to troubleshoot it the issue went away without clear reason why but it’s back again. It’s related to the css file for styling my Netlify CMS preview. When the error doesn’t occur, things work as expected, the preview is styled with my css file.

When it occurs
The error occurs both when I try to run gatsby build locally, or when I clear the cache and deploy on Netlify. If I push a new build without clearing cache on Netlify, it goes through okay. Strangely, I have found that if I clone my repo back down to a new folder and run gatsby build from there, there is no issues. I’m not sure why my original local folder is different, or why the Netlify version is having issues too.

The error

"gatsby-plugin-netlify-cms" threw an error while running the onCreateWebpackConfig lifecycle:

No module factory available for dependency type: CssDependency

  Error: No module factory available for dependency type: CssDependency
  - Compilation.js:800 addDependency
  - Compilation.js:208 iterationOfArrayCallback
  - Compilation.js:816 addDependenciesBlock
  - Compilation.js:827 Compilation.processModuleDependencies
  - Compilation.js:954 afterBuild
  - Compilation.js:998 
  - Compilation.js:734 callback
  - Compilation.js:782 
  - NormalModule.js:478 handleParseResult
  - NormalModule.js:500 
  - NormalModule.js:358 
  - LoaderRunner.js:373 
  - LoaderRunner.js:214 iterateNormalLoaders
  - LoaderRunner.js:186 
  - LoaderRunner.js:111 context.callback
  - loader.js:198 

My config
I have a Gatsby build with Netlify hosting and Netlify CMS using gatsby-plugin-netlify-cms, configured like so in the gatsby-config:

  resolve: 'gatsby-plugin-netlify-cms',
  options: {
    modulePath: `${__dirname}/src/cms/cms.js`,
    htmlTitle: 'My Title'

cms.js referenced above is a very basic file just pointing to a css file for styling the CMS preview:

import CMS from 'netlify-cms-app'

import './cms.css'

Thanks for any help!

Hi @joshunwin can you share your repo?
Does running gatsby clean helps?

I did the following which seems to have solved it:

  1. Remove ‘node modules’ and reinstall.
  2. Update everything: Gatsby, React and Netlify CLI
  3. Deploy with ‘clear cache’ on Netlify.

great! thanks for sharing that.