【问题标题】:gatsby-plugin-mdx cannot find module 'gatsby/webpack'gatsby-plugin-mdx 找不到模块“gatsby/webpack”
【发布时间】:2022-01-11 02:00:12
【问题描述】:

我刚刚将 gatsby-plugin-mdx 添加到我的 gatsby 插件中,但是当我启动项目时,我不断收到此错误。

Error in "/Gatsby/node_modules/gatsby-plugin-mdx/gatsby-node.js": 
Cannot find module 'gatsby/webpack'

我确实注意到有一些版本警告,如下面的警告,但我不确定这是否是问题所在,因为只要 gatsby-plugin-mdx 未添加到 gatsby-config 中,它就可以工作。
我对 gatsby 很陌生,添加的大多数插件都是按照他们的教程来的,所以我真的在这里摸不着头脑。
任何想法是什么导致了这个以及如何解决它?

warn Plugin gatsby-plugin-sass is not compatible with your 
gatsby version 3.14.6 - It requires gatsby@^4.0.0-next

这是我的 package.json

{
  "name": "gatsby",
  "version": "1.0.0",
  "private": true,
  "description": "Gatsby",
  "author": "V",
  "keywords": [
    "gatsby"
  ],
  "scripts": {
    "develop": "gatsby develop",
    "start": "gatsby develop",
    "build": "gatsby build",
    "serve": "gatsby serve",
    "clean": "gatsby clean"
  },
  "dependencies": {
    "@mdx-js/mdx": "^1.6.22",
    "@mdx-js/react": "^1.6.22",
    "@react-three/cannon": "^4.0.1",
    "@react-three/drei": "^7.22.1",
    "@react-three/fiber": "^7.0.19",
    "classnames": "^2.3.1",
    "dayjs": "^1.10.7",
    "framer-motion": "^5.3.0",
    "gatsby": "^3.12.1",
    "gatsby-plugin-gatsby-cloud": "^3.0.0",
    "gatsby-plugin-image": "^1.12.0",
    "gatsby-plugin-layout": "^3.2.0",
    "gatsby-plugin-mdx": "^3.3.0",
    "gatsby-plugin-sass": "^5.1.1",
    "gatsby-plugin-sharp": "^3.12.0",
    "gatsby-source-filesystem": "^4.3.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "sass": "^1.43.4",
    "three": "^0.134.0"
  },
  "devDependencies": {}
}

还有我的 gatsby-config.js

module.exports = {
  siteMetadata: {
    siteUrl: "https://www.yourdomain.tld",
    title: "Gatsby",
  },
  plugins: [
    "gatsby-plugin-gatsby-cloud",
    "gatsby-plugin-image",
    "gatsby-plugin-sharp",
    `gatsby-plugin-sass`,
    "gatsby-plugin-layout",
    {
      resolve: "gatsby-source-filesystem",
      options: {
        name: `src`,
        path: `${__dirname}/src/works/`,
      },
    },
    "gatsby-plugin-mdx" // adding this creates error!
  ],
};

【问题讨论】:

    标签: gatsby gatsby-plugin-mdx


    【解决方案1】:

    如果没有现场查看,很难发现,但我想根本问题是 gatsby-plugin-mdx 版本 (^3.3.0)。根据changelog,发布说明链接到Gatsby v4.3,它与您当前的Gatsby 不兼容,因为您的是3.14.6,并且需要进行重大升级(Gatsby 4)。

    也就是说,您有两个选择:

    • 至少升级 Gatsby 和所有相关依赖项直到版本 4
    • gatsby-plugin-mdx 降级为2.14.0,这显然与您当前的 Gatsby 版本兼容。

    在这两种情况下,您都需要删除 package-lock.json(或 yarn.lock)并将软件包重新安装到所需的版本。

    【讨论】:

    • 哦,谢谢!我刚刚尝试使用yarn upgrade-interactive --latest 升级所有内容,并且成功了!
    猜你喜欢
    • 1970-01-01
    • 2021-07-17
    • 1970-01-01
    • 2021-12-31
    • 2018-02-01
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 2020-06-04
    相关资源
    最近更新 更多