【问题标题】:Gatsby "NetworkError when attempting to fetch resource" when retrieving markdown from Contentful从 Contentful 检索降价时,Gatsby “尝试获取资源时出现网络错误”
【发布时间】:2020-10-04 14:30:34
【问题描述】:

我正在使用 gatsby 入门博客模板,我已经成功地从内容中获取富文本并将其显示在页面上。我现在正在尝试做同样的事情,但使用降价但我收到错误“尝试获取资源时出现 NetworkError”。来自我的 graphql 查询。

我正在尝试按照此处的文档进行操作,因此首先我有一个长文本字段,用于将降价存储在内容丰富的称为“bodym”中。

我的 GraphQL 查询如下,我基本上是在尝试关注 example。我可以从内容中查询降价。

但是,当尝试将其转换为可用的 HTML 时,我收到错误:

我在控制台中得到以下信息:

 ERROR 

The "path" argument must be of type string. Received type undefined

  Error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Recei  ved type undefined

  - validators.js:125 validateString
    internal/validators.js:125:11

  - index.js:68 _callee$
    [faesel-blog]/[gatsby-remark-relative-images]/index.js:68:40

  - index.js:5 asyncGeneratorStep
    [faesel-blog]/[gatsby-remark-relative-images]/index.js:5:103

  - index.js:7 _next
    [faesel-blog]/[gatsby-remark-relative-images]/index.js:7:194

  - index.js:7 
    [faesel-blog]/[gatsby-remark-relative-images]/index.js:7:364

  - new Promise

  - index.js:7 
    [faesel-blog]/[gatsby-remark-relative-images]/index.js:7:97

  - index.js:96 
    [faesel-blog]/[gatsby-remark-relative-images]/index.js:96:22

  - new Promise

  - index.js:47
    [faesel-blog]/[gatsby-remark-relative-images]/index.js:47:12

  - Array.map

  - index.js:46 module.exports
    [faesel-blog]/[gatsby-remark-relative-images]/index.js:46:22

我的代码可以在here找到。

考虑到我能够从内容中检索降价。我猜问题出在 gatsby-source-contentful 插件的某个地方。感谢您的帮助!

【问题讨论】:

    标签: javascript markdown gatsby contentful


    【解决方案1】:

    我发现这是包依赖的问题,代码库最初来自 gatsby starter,为了解决这个问题,我将包依赖更改为以下内容:

    "dependencies": {
        "@contentful/rich-text-from-markdown": "^14.1.1",
        "@contentful/rich-text-react-renderer": "^13.2.0",
        "gatsby": "^2.3.3",
        "gatsby-plugin-react-helmet": "^3.0.12",
        "gatsby-plugin-sass": "^2.0.11",
        "gatsby-plugin-sharp": "^2.0.32",
        "gatsby-remark-images": "^3.0.10",
        "gatsby-remark-relative-images": "^0.2.2",
        "gatsby-source-contentful": "^2.0.47",
        "gatsby-source-filesystem": "^2.0.28",
        "gatsby-transformer-remark": "^2.3.8",
        "node-sass": "^4.11.0",
        "react": "^16.8.6",
        "react-dom": "^16.8.6",
        "react-helmet": "^5.2.0"
      },
    

    然后将依赖升级为以下:

      "dependencies": {
        "@contentful/rich-text-from-markdown": "^14.1.1",
        "@contentful/rich-text-react-renderer": "^13.4.0",
        "gatsby": "^2.23.11",
        "gatsby-plugin-react-helmet": "^3.3.6",
        "gatsby-plugin-sass": "^2.3.6",
        "gatsby-plugin-sharp": "^2.6.14",
        "gatsby-remark-images": "^3.3.13",
        "gatsby-remark-relative-images": "^0.2.3",
        "gatsby-source-contentful": "^2.3.18",
        "gatsby-source-filesystem": "^2.3.14",
        "gatsby-transformer-remark": "^2.8.19",
        "node-sass": "^4.14.1",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "react-helmet": "^5.2.1"
      }
    

    这似乎解决了问题。

    【讨论】:

      猜你喜欢
      • 2019-01-13
      • 2019-09-04
      • 2021-05-23
      • 2020-03-29
      • 2017-07-31
      • 2020-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多