reactjs - 在 Gatsby 中找不到 MDX 模块
问题描述
我正在制作一个 Gatsby 网站,我最初将它设置为通过gatsby-transformer-remark
. 从那以后,我决定将其移至 MDX,以便在我可以使用的内容上有更多的自由。
我已按照本指南将项目从 MD 迁移到 MDX,但我不断收到以下错误:
Cannot find module 'D:\XXXX\XXXX\gatsby\.cache\caches\gatsby-plugin-mdx\webpack\output.js'
Require stack:
- D:\XXXX\XXXX\gatsby\node_modules\gatsby-plugin-mdx\utils\render-html.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby-plugin-mdx\gatsby\source-nodes.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby-plugin-mdx\gatsby-node.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\bootstrap\load-plugins\validate.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\bootstrap\load-plugins\load.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\bootstrap\load-plugins\index.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\services\initialize.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\services\index.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\state-machines\develop\services.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\state-machines\develop\index.js
- D:\XXXX\XXXX\gatsby\node_modules\gatsby\dist\commands\develop-process.js
- D:\XXXX\XXXX\gatsby\.cache\tmp-4452-lp3aICfNr8bo
我试过了:
- 清除缓存和构建文件 (
gatsby clean
) - 更新所有包,包括 Gatsby 本身
- 包含插件的各种方法
gatsby-config.js
- 将其全部更改回 MD,确保它正常工作,然后再次将其迁移到 MDX。
- 做一个构建。与运行时发生相同的事情
gatsby develop
- 删除 package-lock.json 和 node_modules 文件夹并
npm install
再次运行。
没有任何效果。这对于 NPM 或 Webpack 来说一定是一件非常愚蠢的事情,但我只是看不到它。
盖茨比-config.js
module.exports = {
siteMetadata: {
title: "XXXX",
copyright: "XXXX"
},
plugins: [
{
resolve: `gatsby-plugin-mdx`,
options: {
extensions: [`.md`, `.mdx`],
},
},
`gatsby-transformer-remark`,
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
`gatsby-transformer-sharp`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `src`,
path: `${__dirname}/src/`,
},
},
]
}
包.json
{
"name": "gatsby-starter-hello-world",
"private": true,
"description": "A simplified bare-bones starter for Gatsby",
"version": "0.1.0",
"license": "0BSD",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
},
"dependencies": {
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"gatsby": "^3.1.2",
"gatsby-plugin-image": "^1.1.2",
"gatsby-plugin-mdx": "^2.1.0",
"gatsby-plugin-sharp": "^3.1.2",
"gatsby-source-filesystem": "^3.1.0",
"gatsby-transformer-remark": "^3.1.0",
"gatsby-transformer-sharp": "^3.1.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-in-viewport": "^1.0.0-alpha.16",
"react-reveal-text": "^0.1.1",
"react-spring": "^8.0.27",
"react-text-loop": "^2.3.0"
},
"devDependencies": {
"prettier": "2.2.1"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
}
}
编辑:我应该指出,当我转到错误中提到的缓存中的那个位置时,确实没有 webpack 文件夹,也没有 output.js - 所以当我运行时它真的没有生成gatsby develop
,我只是无法理解为什么。
我还尝试通过克隆官方 gatsby mdx 入门模板来创建一个新项目,并且开箱即用。
解决方案
推荐阅读
- java - 如何让 Emoji 在 Mac OS 上的 Java Swing 小部件中呈现?
- autohotkey - 将一个函数的输出作为参数传递给另一个函数
- node.js - FetchError:对 https://discord.com/api/v7/gateway/bot 的请求失败,原因:无法获取本地颁发者证书
- php - 新创建的 PHP Codeception 项目正在运行,没有错误输出
- ruby - 有没有办法在不使用 3 个收集器来组合字符串的情况下重构它?
- excel - 在 Excel 上创建一组合并的对
- python - 使用迭代器创建正则表达式模式
- responsive-design - CSS 打破媒体内容而不是屏幕大小
- clickhouse - Clickhouse:滑动/移动窗口
- jq - jq + 运算符是否渴望?