Code Monkey home page Code Monkey logo

Comments (9)

mlynam avatar mlynam commented on July 30, 2024 5

You need to modify your netlify config.

    {
      resolve: "gatsby-plugin-netlify-cms",
      options: {
        modulePath: `${__dirname}/src/cms/cms.js`,
        customizeWebpackConfig: config => {
          config.node = {
            ...config.node,
            fs: "empty",
            child_process: "empty",
            module: "empty",
          };
        },
      },
    },

You should probably include this as the last plugin listed in gatsby-config.js

from gatsby-mdx-netlify-cms-starter.

mlynam avatar mlynam commented on July 30, 2024 2

I can shed more light on the problem. Gatsby has 2 major build steps.

Step 1 runs entirely in node and is responsible for validating schema, running queries, loading data, performing SSR to generate the static elements and so on.

During step 2, Gatsby builds the site with a browser config because it expects there may be some elements that are intended to run in the browser (like dynamically loaded data at runtime, or maybe a netlify admin application!). This 2nd stage is what dies if you included a gatsby symbol inside some component that gatsby doesn't handle during Stage 1. In the case of this starter, any component you expose to your CMS like previews, mdx shortcodes and editors will complain if you don't stub those node modules inside your netlify plugin config.

from gatsby-mdx-netlify-cms-starter.

leafac avatar leafac commented on July 30, 2024 1

@mysterybear: The progress I made on the issue is that I think I now understand why it occurs in the first place. In this starter there’s code like this that requires MDX. This code is being interpreted as if it were running on the browser. Of course, this is Gatsby we’re talking about, and Gatsby precompiles stuff during build time to generate a static site. But still, the code behaves as if it were interpreted in the browser. The problem is that MDX seems to use fs, child_process, and other things that you only find in Node.js, not on the browser.

The solution seems to be to tell webpack (which Gatsby is using under the hood) to provide an empty implementation of those libraries, only to get MDX going. (This isn’t just an issue with MDX; it also applies to other libraries that may be using things from Node.js.)

from gatsby-mdx-netlify-cms-starter.

leafac avatar leafac commented on July 30, 2024

Same issue here. Did you close the issue because you solved it? How? Could this be a solution?

from gatsby-mdx-netlify-cms-starter.

mysterybear avatar mysterybear commented on July 30, 2024

Tried adding

// gatsby-node.js
exports.onCreateWebpackConfig = ({ actions }) => {
  actions.setWebpackConfig({
    node: {
      fs: 'empty'
    }
  })
}

No joy, any luck you guys @leafac @jesterbeaver or any advice from @renvrant ? Could we re-open this otherwise?

Cheers

from gatsby-mdx-netlify-cms-starter.

mysterybear avatar mysterybear commented on July 30, 2024

Thanks for the quick response @mlynam !

This seems resolved with your addition plus the similar code for gatsby-node.js

Submitted PR #8 feel free to merge or close if I'm missing some valid reason this wasn't in the repo before @renvrant

from gatsby-mdx-netlify-cms-starter.

mlynam avatar mlynam commented on July 30, 2024

@mysterybear you shouldn't need it in the root node config unless there is another unmentioned dependency running around.

from gatsby-mdx-netlify-cms-starter.

mysterybear avatar mysterybear commented on July 30, 2024

@mysterybear you shouldn't need it in the root node config unless there is another unmentioned dependency running around.

Seems to be. If I remove it from gatsby-node.js, I get the same problem:

failed Building production JavaScript and CSS bundles - 116.667s
 ERROR #98123  WEBPACK

Generating JavaScript bundles failed

Can't resolve 'fs' in 'node_modules/@mdx-js/mdx/node_modules/@babel/core/lib/transformation'

File: node_modules/@mdx-js/mdx/node_modules/@babel/core/lib/transformation/normalize-file.js

from gatsby-mdx-netlify-cms-starter.

mlynam avatar mlynam commented on July 30, 2024

Interesting. Thanks for the correction!

from gatsby-mdx-netlify-cms-starter.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.