标签: gatsby-plugin

“gatsby-source-contentful”的插件选项无效

我在尝试打开通过 GitHub 分叉的项目时遇到以下错误。

success open and validate gatsby-configs - 0.492s

 ERROR #11331  PLUGIN

Invalid plugin options for "gatsby-source-contentful":

- "accessToken" is required

not finished load plugins - 6.220s
Run Code Online (Sandbox Code Playgroud)

我已经进行了多次编辑,但无法处理该项目,因为我目前无法打开它。我确实有一个内容丰富的帐户,但对 Gatsby 相当陌生,并且不知道如何为accessToken.

我需要通过 来执行此操作process.env,还是我完全错过了该过程?

谢谢,如有任何帮助,我们将不胜感激。

access-token reactjs contentful gatsby gatsby-plugin

9
推荐指数
1
解决办法
4585
查看次数

如何使用 allMdx 查询中的“gatsby-plugin-mdx”渲染 MDX?

我想直接从allMdx查询返回的列表中呈现 MDX 内容。我将“gatsbyjs”与“gatsby-plugin-mdx”一起使用。

我们来查询一下:

export const query = graphql`
  query MyQuery {
    allMdx {
      nodes {
        id
        body
        frontmatter {
          title
          slug
        }
      }
    }
  }
`;
Run Code Online (Sandbox Code Playgroud)

从官方文档中可以看出https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#updating-page-templates <MDXRenderer>组件已被删除。所以不再可能做这样的事情:

{data.allMdx.nodes.map((n) => (
    <MDXRenderer>{n.body}</MDXRenderer>
))}
Run Code Online (Sandbox Code Playgroud)

相反,现在需要这样做:

function MyComponent({ children }) {
  return (
    <div>
      {children}
    </div>
  );
}
Run Code Online (Sandbox Code Playgroud)

但我想渲染 MDX,allMdx以便我有一个 MDX 帖子列表,例如,你们知道这是否可能以及如何做到吗?

javascript markdown reactjs gatsby-plugin

8
推荐指数
0
解决办法
627
查看次数

Gatsby - 将 Google 字体添加到 Gatsby 站点

我正在尝试在我的 Gatsby 站点中添加 Google 字体 (Mukta Malar)。

我看过很多关于将 Google 字体添加到 Gatsby 站点的文章,其中大多数似乎都使用了这个插件:gatsby-plugin-prefetch-google-fonts

我在我的网站中使用了上述插件,将其添加到gatsby-config.js文件中:

plugins: [
    {
      resolve: `gatsby-plugin-prefetch-google-fonts`,
      options: {
        fonts: [
          {
            family: `Mukta Malar`
          },
        ],
      },
    }
  ]
Run Code Online (Sandbox Code Playgroud)

并将字体系列添加到我的 css 文件中:

* {
  font-family: "Mukta Malar", sans-serif;
}
Run Code Online (Sandbox Code Playgroud)

但谷歌字体不适用于该网站。我的代码中是否缺少隐藏的步骤?

css gatsby google-fonts gatsby-plugin

6
推荐指数
1
解决办法
1879
查看次数

GitHub Actions 失败并出现 Gatsby 错误:输入文件包含不受支持的图像格式

我的网站使用 Gatsby 和 NetlifyCMS,目前在GitHub Actions运行工作流程时收到以下错误消息:

error "gatsby-plugin-manifest" threw an error while running the onPostBootstrap lifecycle:

Error: Input file contains unsupported image format
Run Code Online (Sandbox Code Playgroud)

很奇怪的是,在我的本地系统上使用gatsbydevelopgatsbybuild并没有出现该错误

我的插件数组如下所示:

plugins: [
    {
      resolve: `gatsby-plugin-typography`,
      options: {
        pathToConfigModule: `src/utils/typography`,
      },
    },
    {
      // keep as first gatsby-source-filesystem plugin for gatsby image support
      resolve: "gatsby-source-filesystem",
      options: {
        path: `${__dirname}/static/img`,
        name: "uploads",
      },
    },
    `gatsby-plugin-smoothscroll`,
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-twitter`,
    {
      resolve: "gatsby-plugin-netlify-cms",
      options: {
        modulePath: `${__dirname}/src/cms/cms.js`,
        htmlFavicon: `src/images/favicon.png`,
      },
    },
    `gatsby-plugin-no-index`,
    `gatsby-plugin-transition-link`, …
Run Code Online (Sandbox Code Playgroud)

gatsby netlify github-actions gatsby-image gatsby-plugin

6
推荐指数
1
解决办法
3052
查看次数

Gatsby SCSS 模块未编译

运行 Gatsby 版本 3.0.1,使用 sass 1.32.8。我刚刚开始玩一些东西,我遇到了一个我无法解决的奇怪问题。

./gatsby-config.js

module.exports = {
  /* Your site config here */
  plugins: [
    {
      resolve: `gatsby-plugin-sass`,
      options: {
        implementation: require("sass"),
      },
    },
  ],
}
Run Code Online (Sandbox Code Playgroud)

./src/pages/index.js

import React from "react"
import homeStyles from '../styles/scss/index.module.scss'

export default function Home() {
  return <div className={homeStyles.testElement}>Hello world!</div>
}
Run Code Online (Sandbox Code Playgroud)

./styles/scss/index.module.scss

.testElement {
  font-size: 72px;
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是Attempted import error: '../styles/scss/index.module.scss' does not contain a default export (imported as 'homeStyles').

如果我尝试import * as homeStyles from '../styles/scss/index/module.scss错误是:Attempted import error: 'testElement' …

gatsby gatsby-plugin

6
推荐指数
1
解决办法
2261
查看次数

Typescript 和 Gatsby:gatsby-plugin-ts + graphQL 查询集成

我用来gatsby-plugin-ts为我的 graphql 页面查询生成类型。

我遇到的问题是,生成的所有类型都会返回T | undefined所有字段的类型,因此我需要在任何组件中使用它们之前检查所有查询子字段,否则编译器将引发错误。

gatsby-plugin-image个例子。给出一个查询:

export const query = graphql`
  query IndexPage {
    banner: file(relativePath: { eq: "banner.jpg" }) {
      childImageSharp {
        gatsbyImageData(width: 1920)
      }
    }
  }
`;
Run Code Online (Sandbox Code Playgroud)

结果data.banner应该传递给getImage函数,但如果您尝试这样做,打字稿可以理解地抛出以下错误,因为 undefined 不能分配给IGAtsbyImageData预期的getImage 打字稿错误

当涉及更复杂的查询(例如来自 markdownremark 插件的查询)时,情况会更糟:每次都需要手动检查一个查询结果的所有子字段。有解决办法吗?

typescript reactjs graphql gatsby gatsby-plugin

6
推荐指数
1
解决办法
649
查看次数

如何在 Gatsby-plugin-image 中将图像路径作为 Gatsby 中的 prop 传递

我正在尝试将图像的路径作为道具传递给组件

注意:组件和索引页都可以通过相同的路径访问图像。当我将路径作为道具传递时它不起作用

在下面的代码中,我尝试使用 GatbsyImage 和 StaticImage 标签似乎都失败了

索引.js

import React from "react";
import 'bootstrap/dist/css/bootstrap.min.css';
import '../styles/index.scss';
import Main from  '../Layouts/main';
import ImageOverlay from '../components/ImageOverlay';
import { StaticImage } from "gatsby-plugin-image"

function Home(){
  // Home page images
  return (
    <Main >
    <section className="home_page">
      <ImageOverlay path="../images/home/places/portblair.png"> </ImageOverlay>
    </section>
    </Main>
  )
}

export default Home
 
Run Code Online (Sandbox Code Playgroud)

组件/ImageOverlay.js

import React from 'react';
import { GatsbyImage, StaticImage } from "gatsby-plugin-image"
const ImageOverlay = ({path}) =>{
    return(

      <div>
          <GatsbyImage image={path}></GatsbyImage>
          <StaticImage src={path}></StaticImage>
      </div> 
  
    )
}
export default …
Run Code Online (Sandbox Code Playgroud)

gatsby gatsby-image gatsby-plugin

6
推荐指数
1
解决办法
4267
查看次数

sassOptions 中的数据选项在升级到 v3 后停止在 gatsby-plugin-sass 中工作,并用 sass 替换了 node-sass

我决定node-sass从我的 gatsby 项目中删除并使用sass。我遵循了此处针对 v3提到的内容。我删除了node-sass,现在我有这些版本package.json

"gatsby-plugin-sass": "3.1.0",
"sass": "1.32.5",
Run Code Online (Sandbox Code Playgroud)

我需要能够一次性为全局变量/mixins/函数编写一些 @use 或 @import 规则,以便我可以在所有 scss 文件中使用它们,因此我不必一遍又一遍地重复相同的规则。

有了node-sass这样的工作:

{
  resolve: `gatsby-plugin-sass`,
  options: {
    includePaths: [`${__dirname}/src/styles`],
    data: `@import "globals.scss";`,
  },
},
Run Code Online (Sandbox Code Playgroud)

升级后,该includePaths属性有效但data无效,我从我的 scss 文件中收到有关“丢失”变量的错误:

{
  resolve: `gatsby-plugin-sass`,
  options: {
    sassOptions: {
      includePaths: [`${__dirname}/src/styles`],
      data: `@use 'globals' as *;`,
    },
  },
},
Run Code Online (Sandbox Code Playgroud)

如果我@use 'globals' as *;在每个 scss 文件中插入规则,错误就会消失,一切都按预期工作,但我不想插入这一行并修改我所有的 sass 文件。

我很确定这个问题sass-loader与此声明(文档)有关,但我无法弄清楚如何使其工作以及为什么它以前有效:

?? …

sass sass-loader gatsby gatsby-plugin

5
推荐指数
1
解决办法
472
查看次数

斯特拉皮和盖茨比形象问题

我一直在执行以下步骤:https://github.com/strapi/gatsby-source-strapi 由于 image >> publicURL 也不起作用,我已经重新安装了最新版本的 gatsby-source-strapi,以便能够获取 publicURL。不过,这会通过本地文件......

这是我的 gatsby-config.js

module.exports = {
  plugins: [
    "gatsby-plugin-react-helmet",
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    {
      resolve: "gatsby-source-strapi",
      options: {
        apiURL:  "http://localhost:1337",
        contentTypes: ["articles"],
        singleTypes: [`homepage`, `global`],
        queryLimit: 1000,
      },
    },
    "gatsby-plugin-postcss",
  ],
};
Run Code Online (Sandbox Code Playgroud)

我的博客页面如下所示

import React from 'react';
import Footer from '../partials/Footer';
import Navbar from '../partials/Navbar';

import { StaticQuery, graphql } from 'gatsby';

const query = graphql`
  query {
    allStrapiArticles{
      edges {
        node {
          strapiId
          title …
Run Code Online (Sandbox Code Playgroud)

strapi gatsby gatsby-plugin

5
推荐指数
1
解决办法
2282
查看次数

gatsby-plugin-image 未通过 npm 安装

我正在尝试根据文档https://www.gatsbyjs.com/plugins/gatsby-plugin-image#installation通过 npm 安装 gatsby-plugin-image

在终端中收到以下错误:

$ npm install gatsby-plugin-image gatsby-plugin-sharp gatsby-source-filesystem gatsby-transformer-sharp
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: gatsby-starter-hello-world@0.1.0
npm ERR! Found: gatsby@2.32.9
npm ERR! node_modules/gatsby
npm ERR!   gatsby@"^2.26.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer gatsby@"^3.0.0-next.0" from gatsby-plugin-image@1.0.0
npm ERR! node_modules/gatsby-plugin-image
npm ERR!   gatsby-plugin-image@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or …
Run Code Online (Sandbox Code Playgroud)

gatsby gatsby-image gatsby-plugin

4
推荐指数
1
解决办法
1749
查看次数