Cannot find module '@mdx-js/mdx' - Gatsby

Viewed 3311

After the last update of today i'm getting this error. I'm using no MDX in my project howsoever..

npm run develop produces this issue, does someone has some knowledge about this?

internal/modules/cjs/loader.js:979
  throw err;
  ^

Error: Cannot find module '@mdx-js/mdx'
Require stack:
- /Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/transform-recipe-mdx.js
- /Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/renderer/index.js
- /Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/validate-steps.js
- /Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/recipe-machine/index.js
- /Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/graphql-server/server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15)
    at Function.Module._load (internal/modules/cjs/loader.js:859:27)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/transform-recipe-mdx.js:12:35)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/transform-recipe-mdx.js',
    '/Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/renderer/index.js',
    '/Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/validate-steps.js',
    '/Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/recipe-machine/index.js',
    '/Users/mikey/Sites/Gimmix/node_modules/gatsby-recipes/dist/graphql-server/server.js'
  ]
}
5 Answers

Problem is solved with the latest update(s):

gatsby@2.24.5 (gatsby-plugin-sharp@2.6.33) (gatsby-source-contentful@2.3.43) (gatsby-transformer-remark@2.8.34)

delete your cache gatsby clean

Be sure to also update your gatsby-cli: npm i -g gatsby-cli

delete your node_modules & packages for a clean install rm -rf node_modules package-lock.json

last but not least npm install --save

and test your building proces npm run develop

I would recommend downgrading to your latest stable version of your Gatsby dependency (to v2.24.37). It seems to be a common issue in ^2.24.54 versions. As you may guess, although you are not using the @mdx-js/mdx package, it's a dependency used by Gatsby itself.

In the upgrade process for any package, when a dependency is upgraded doesn't mean that all their sub-depenencies work because of the needs of each project. It may take a few days/weeks to work for all packages. That's why you should ensure in a gatsby dev and gatsby build that the project works before committing and pushing anything to the repository.

If you haven't committed the upgrade, just rollback the tracked files (git checkout . or git reset --hard), remove your node_modules and run a npm install command to keep the project in your stable running version.

If you have committed your files, run npm install gatsby@2.24.37 to downgrade your Gatsby version (or fix it in your package.json) and run a npm install again.


I saw in your comments that you have the dependency in your package.json but you are not using it. In that case remove it by npm uninstall @mdx-js/mdx.

Running yarn add @mdx-js/mdx fixed it for me.

You first make sure that all dependencies are installed properly.

You can check that is this module installed or not by importing import {<name>} from '@mdx-js'

If it doesn't break it means that it is installed already. Or if it breaks then run npm install to install all the listed dependencies.

You can move forward and check that this package has that file or data that you want.

You can check this with import {<name>} from '@mdx-js/mdx'. You can also check this with navigating to node_modules/@mdx-js/mdx directory. You will find some names of data you can use, functions or objects etc. Name must match from one of the data type else you have a typo when you are importing something.

Note: this is a general debugging approach for node_modules

run yarn run build and fix those errors. That fixed my problem!

Related