Cannot find module '@mdx-js/mdx' - Gatsby
Asked Answered
S

5

15

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'
  ]
}
Steep answered 7/9, 2020 at 16:14 Comment(4)
What update are you meaning?Orethaorferd
@FerranBuireu "gatsby": "^2.24.54", "gatsby-transformer-remark": "^2.8.33", "gatsby-source-filesystem": "^2.3.28" etc...Steep
I get this exact error when I upgrade gatsby from 2.24.37 to 2.24.54. I have never used MDX either but the error points at mdx-js being a dependency of gatsby-recipes which must be a dependency of gatsby itself I'd guess.Succumb
@Succumb I think it's an error/bug from gatsby itself, and we have to wait for a fix in the coming updates. (?) so don't push your files live, keep them local.Steep
S
10

Problem is solved with the latest update(s): 😁

[email protected] ([email protected]) ([email protected]) ([email protected])

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

Steep answered 9/9, 2020 at 3:37 Comment(0)
O
1

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 [email protected] 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.

Orethaorferd answered 7/9, 2020 at 17:7 Comment(3)
Yes. I haven't pushed it yet. Thanks for the tip. I will wait for the next update to come and keep the files locally. And I said I don't have the package in my list, so thats why i find it strange.. But even that isn't the problem, cause the "mdx/js" was in my node_modules before the whole update. So the update is just messy at this moment..Steep
In that case just rollback your local changes, delete your node_modules and run npm install. Because it's a dev dependency of Gatsby it will be in your modules but with the correct version.Orethaorferd
I have, but still bumb into the same warning. Its a gatsby bug, i think..Steep
I
1

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

Infante answered 8/9, 2020 at 16:22 Comment(1)
Thanks for the effort, i didn't tried it because Gatsby already fixed it with the latest update(s).Steep
P
0

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

Punctilious answered 7/9, 2020 at 16:37 Comment(5)
Thanks, i'm a newbie. Saw your first deleted post my friend. Don't worry, can have it. 🤣 Not sure if i understand you but I'm not using any MDX or markdown files in my project, everything comes from a headless CMS. Why calling it then? I saw howsoever that after deleting and reinstalling (for updating) my packages (what i always do), it added the '@mdx-js/mdx' to the package.lock.json. Now its expecting me to use it.Steep
correction: *I saw howsoever that after deleting and reinstalling (for updating) my packages (what i always do), it updated the '@mdx-js/mdx' in the package.lock.json.Steep
If saying you a newbie hearted, I apologise. Can you please share your package.json file here?Punctilious
I cannot paste it in here, its has too many characters. I'm really a newbie on Stackoverflow, eventhough im here for years. Do you know another way to share it.. (?)Steep
Aaah good one, thanks I will in the future, for now its fixed.Steep
M
-1

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

Myrmecophagous answered 9/9, 2022 at 3:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.