我在尝试打开通过 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
,还是我完全错过了该过程?
谢谢,如有任何帮助,我们将不胜感激。
我想直接从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 帖子列表,例如,你们知道这是否可能以及如何做到吗?
我正在尝试在我的 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)
但谷歌字体不适用于该网站。我的代码中是否缺少隐藏的步骤?
我的网站使用 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)
很奇怪的是,在我的本地系统上使用gatsbydevelop和gatsbybuild并没有出现该错误
我的插件数组如下所示:
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 版本 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-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 插件的查询)时,情况会更糟:每次都需要手动检查一个查询结果的所有子字段。有解决办法吗?
我正在尝试将图像的路径作为道具传递给组件
注意:组件和索引页都可以通过相同的路径访问图像。当我将路径作为道具传递时它不起作用
在下面的代码中,我尝试使用 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) 我决定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
与此声明(文档)有关,但我无法弄清楚如何使其工作以及为什么它以前有效:
?? …
我一直在执行以下步骤: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) 我正在尝试根据文档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-plugin ×10
gatsby ×9
gatsby-image ×3
reactjs ×3
access-token ×1
contentful ×1
css ×1
google-fonts ×1
graphql ×1
javascript ×1
markdown ×1
netlify ×1
sass ×1
sass-loader ×1
strapi ×1
typescript ×1