1

我刚刚将 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!
  ],
};
4

1 回答 1

2

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

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

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

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

于 2021-12-06T09:58:27.323 回答