GVKun编程网logo

Gatsby + Reach 路由器:控制客户端路由路径的最佳模式(路由控制工具)

1

对于想了解Gatsby+Reach路由器:控制客户端路由路径的最佳模式的读者,本文将是一篇不可错过的文章,我们将详细介绍路由控制工具,并且为您提供关于'gatsby-source-graphql'导致

对于想了解Gatsby + Reach 路由器:控制客户端路由路径的最佳模式的读者,本文将是一篇不可错过的文章,我们将详细介绍路由控制工具,并且为您提供关于'gatsby-source-graphql' 导致加载插件错误引用 'gatsby/graphql' 我将它包含在我的 gatsby-config.js 中,如下所示:但它产生了这个错误:我尝试过的:我使用 gatsby info --clipboard 的环境报告是:有什么想法吗?导致问题的原因如下:、Gatsby (gatsby-source-strapi) - 您的数据问题中存在冲突的字段类型、Gatsby - webpack 无法使用 `gatsby-plugin-alias-imports`、Gatsby Develop 工作正常,Gatsby Build 导致 WebpackError: Minified React error #130的有价值信息。

本文目录一览:

Gatsby + Reach 路由器:控制客户端路由路径的最佳模式(路由控制工具)

Gatsby + Reach 路由器:控制客户端路由路径的最佳模式(路由控制工具)

如何解决Gatsby + Reach 路由器:控制客户端路由路径的最佳模式

我的目标是在使用 Gatsby (v2) 和 @reach/router 时以最佳模式启用以下类型的静态和动态路径。我遇到的问题是 Gatsby 文档将您设置为在每个动态路由上添加路径 /app 的前缀,这不适合我的用例。

所需路径:

  • /:静态路由和构建时生成
  • /about:静态路由和构建时生成
  • /:username:动态路由和运行时生成
  • /:username/:postTitleSlug:动态路由和运行时生成

按照 Gatsby 文档,我有这个文件夹结构:

/pages
  index.jsx
  about.jsx
  app.jsx
/templates
  profile.jsx // for the /:username path
  post.jsx // for the /:username/:postTitleSlug path

app.jsx

const Routes = () => (
  <Router>
    <Profile path="/:username" />
    <Read path="/:username/:slug" />
  </Router>
);

gatsby-node.js

exports.onCreatePage = async ({ page,actions }) => {
  const { createPage } = actions;

  if (page.path.match(/^\\/app/)) {
    await createPage({
      path: ''app'',matchPath: ''/app/*'',component: path.resolve(''src/templates/Profile/index.js''),});
  }
};

是否可以取消“应用”命名法并在基本路径 / 之外键入一些动态路由?

FWIW,我的第一个尝试修复是使 pages/index.jsx 只是一个路由器,类似于 this post。这似乎是一个潜在的解决方案,但我不清楚 gatsby-node.js 所需的更新。

'gatsby-source-graphql' 导致加载插件错误引用 'gatsby/graphql' 我将它包含在我的 gatsby-config.js 中,如下所示:但它产生了这个错误:我尝试过的:我使用 gatsby info --clipboard 的环境报告是:有什么想法吗?导致问题的原因如下:

'gatsby-source-graphql' 导致加载插件错误引用 'gatsby/graphql' 我将它包含在我的 gatsby-config.js 中,如下所示:但它产生了这个错误:我尝试过的:我使用 gatsby info --clipboard 的环境报告是:有什么想法吗?导致问题的原因如下:

如何解决''gatsby-source-graphql'' 导致加载插件错误引用 ''gatsby/graphql'' 我将它包含在我的 gatsby-config.js 中,如下所示:但它产生了这个错误:我尝试过的:我使用 gatsby info --clipboard 的环境报告是:有什么想法吗?导致问题的原因如下:

我已经添加了一个可用的 Gatsby 安装,但是,在尝试构建一些 graphQL 构建时数据获取时,我遇到了一个问题,该问题导致错误运行 npm start (gatsby develop)gatsby build

我按照此处的说明安装了 gatsby-source-graphql: https://www.npmjs.com/package/gatsby-source-graphql

我将它包含在我的 gatsby-config.js 中,如下所示:

  1. module.exports = {
  2. // Optional
  3. siteMetadata: {
  4. title: `Title from siteMetadata`,},plugins: [
  5. {
  6. resolve: `gatsby-plugin-manifest`,options: {
  7. name: "Project Template",short_name: "PT",start_url: "/",background_color: "#6b37bf",theme_color: "#6b37bf",// Enables "Add to Homescreen" prompt and disables browser UI (including back button)
  8. // see https://developers.google.com/web/fundamentals/web-app-manifest/#display
  9. display: "standalone",icon: "src/images/icon.png",// This path is relative to the root of the site.
  10. // An optional attribute which provides support for CORS check.
  11. // If you do not provide a crossOrigin option,it will skip CORS for manifest.
  12. // Any invalid keyword or empty string defaults to `anonymous`
  13. crossOrigin: `use-credentials`,{
  14. resolve: `gatsby-source-filesystem`,options: {
  15. name: `images`,path: `${__dirname}/src/images`,// GraphQL APIs for use during build-time.
  16. // https://www.npmjs.com/package/gatsby-source-graphql
  17. //////////////////////////////////////////////////////
  18. {
  19. resolve: "gatsby-source-graphql",options: {
  20. // Arbitrary name for the remote schema Query type
  21. typeName: "SpaceX",// Field under which the remote schema will be accessible. You''ll use this in your Gatsby query
  22. fieldName: "spaceX",// Url to query from
  23. url: "https://api.spacex.land/graphql/",// {
  24. // resolve: "gatsby-source-graphql",// options: {
  25. // // Arbitrary name for the remote schema Query type
  26. // typeName: "SWAPI",// // Field under which the remote schema will be accessible. You''ll use this in your Gatsby query
  27. // fieldName: "swapi",// // Url to query from
  28. // url: "https://swapi-graphql.netlify.app/.netlify/functions/index",// },// },`gatsby-transformer-sharp`,`gatsby-plugin-sharp`,`gatsby-plugin-react-helmet`,`gatsby-theme-material-ui`,{
  29. resolve: `gatsby-plugin-nprogress`,options: {
  30. // Setting a color is optional.
  31. color: `tomato`,// disable the loading spinner.
  32. showSpinner: false,`gatsby-plugin-transition-link`,`gatsby-plugin-layout`,// Trial and error showed this needs to be last (But that doesn''t mean it will always work in the dev environment,try npm run clean or if that fails - test in build)
  33. ],}

但它产生了这个错误:

  1. Error in "/Users//Documents/projects/project/node_modules/gatsby-source-graphql/gatsby-node.js":
  2. Cannot find module ''gatsby/graphql''
  3. Error: Cannot find module ''gatsby/graphql''
  4. - loader.js:636 Function.Module._resolveFilename
  5. internal/modules/cjs/loader.js:636:15
  6. - loader.js:562 Function.Module._load
  7. internal/modules/cjs/loader.js:562:25
  8. - loader.js:692 Module.require
  9. internal/modules/cjs/loader.js:692:17
  10. - v8-compile-cache.js:159 require
  11. [client]/[v8-compile-cache]/v8-compile-cache.js:159:20
  12. - gatsby-node.js:8 Object.<anonymous>
  13. [tbwa-project-template]/[gatsby-source-graphql]/gatsby-node.js:8:5
  14. - v8-compile-cache.js:178 Module._compile
  15. [client]/[v8-compile-cache]/v8-compile-cache.js:178:30
  16. - loader.js:789 Object.Module._extensions..js
  17. internal/modules/cjs/loader.js:789:10
  18. - loader.js:653 Module.load
  19. internal/modules/cjs/loader.js:653:32
  20. - loader.js:593 tryModuleLoad
  21. internal/modules/cjs/loader.js:593:12
  22. - loader.js:585 Function.Module._load
  23. internal/modules/cjs/loader.js:585:3
  24. - loader.js:692 Module.require
  25. internal/modules/cjs/loader.js:692:17
  26. - v8-compile-cache.js:159 require
  27. [client]/[v8-compile-cache]/v8-compile-cache.js:159:20
  28. - resolve-module-exports.ts:197 resolveModuleExports
  29. [client]/[gatsby]/src/bootstrap/resolve-module-exports.ts:197:26
  30. - validate.ts:348 forEach
  31. [client]/[gatsby]/src/bootstrap/load-plugins/validate.ts:348:31
  32. - Array.forEach
  33. - validate.ts:340 collatePluginAPIs
  34. [client]/[gatsby]/src/bootstrap/load-plugins/validate.ts:340:20
  35. not finished load plugins - 0.727s
  36. npm ERR! code ELIFECYCLE
  37. npm ERR! errno 1
  38. npm ERR! project-template@1.0.0 start: `gatsby develop`
  39. npm ERR! Exit status 1
  40. npm ERR!
  41. npm ERR! Failed at the project-template@1.0.0 start script.
  42. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  43. npm ERR! A complete log of this run can be found in:
  44. npm ERR! /Users/_logs/2021-02-04T00_31_34_070Z-debug.log

我尝试过的:

  • 我在配置中尝试了两种不同的 gatsby-source-graphql 定义(一次只有一种),但都产生了错误。第二个(上面已注释掉)直接取自 The github page example 和 Gatsby example。

  • 我已经尝试更改插件的顺序(我已经尝试了所有位置),但仍然出现错误。

  • 如果我在配置中评论任何和所有 gatsby-source-graphql 部分,它不会产生错误。

  • 如果我注释掉所有插件除了 gatsby-source-graphql 部分之一,我仍然得到完全相同的错误。

  • 我也试过删除 node_modules 文件夹,运行 npm run clean,然后再次 npm install 没有任何变化。

  • 我也尝试了以下链接中描述的 DanceParty 解决方案,没有任何变化: https://github.com/gatsbyjs/gatsby/issues/8249

  • 我试过运行 npm updatenpm install npm@latest -g,但没有看到任何变化。

我使用 gatsby info --clipboard 的环境报告是:

  1. System:
  2. OS: macOS 10.15.7
  3. cpu: (4) x64 Intel(R) Core(TM) i5-6287U cpu @ 3.10GHz
  4. Shell: 5.7.1 - /bin/zsh
  5. Binaries:
  6. Node: 10.23.1 - /usr/local/bin/node
  7. npm: 6.14.10 - /usr/local/bin/npm
  8. Languages:
  9. Python: 2.7.16 - /usr/bin/python
  10. browsers:
  11. Chrome: 88.0.4324.96
  12. Firefox: 85.0
  13. Safari: 14.0.2
  14. npmPackages:
  15. gatsby: ^2.26.1 => 2.32.0
  16. gatsby-image: ^2.10.0 => 2.11.0
  17. gatsby-plugin-layout: ^1.9.0 => 1.10.0
  18. gatsby-plugin-manifest: ^2.11.0 => 2.12.0
  19. gatsby-plugin-material-ui: ^2.1.10 => 2.1.10
  20. gatsby-plugin-nprogress: ^2.9.0 => 2.10.0
  21. gatsby-plugin-react-helmet: ^3.8.0 => 3.10.0
  22. gatsby-plugin-sharp: ^2.13.0 => 2.14.0
  23. gatsby-plugin-transition-link: ^1.20.5 => 1.20.5
  24. gatsby-source-filesystem: ^2.10.0 => 2.11.0
  25. gatsby-theme-material-ui: ^1.0.13 => 1.0.13
  26. gatsby-transformer-sharp: ^2.11.0 => 2.12.0
  27. npmGlobalPackages:
  28. gatsby-cli: 2.19.0

有什么想法吗?

解决方法

我开始创建一个最小的复制品,然后将所有内容一个一个地添加回去,但我决定在我的第一个设置中玩得更多一些......我很高兴我做到了。

导致问题的原因如下:

此 Gatsby 安装是我们使用的项目模板的一部分,其中包括后端代码、前端、管道部署脚本等。 结构类似于:

ProjectTemplate 文件夹

  • 客户端文件夹
  • 服务器文件夹
  • 其他文件夹

Gatsby 安装位于客户端文件夹中,但有时我需要进入根文件夹执行某些操作。

所以发生了什么事!?

我不小心将 gatsby-source-graphql 安装到根文件夹而不是客户端文件夹。就这样。 我应该在运行 gatsby info --clipboard 时选择它,因为它显然没有列为依赖项。

Gatsby (gatsby-source-strapi) - 您的数据问题中存在冲突的字段类型

Gatsby (gatsby-source-strapi) - 您的数据问题中存在冲突的字段类型

如何解决Gatsby (gatsby-source-strapi) - 您的数据问题中存在冲突的字段类型?

我使用 Gatsby 和 Strapi 已经有一段时间了。

我们一直在使用 gatsby-source-graphql 直到几天前,由于 gatsby-source-graphql 无法与 Gatsby Live Preview 配合使用,公司决定改用 gatsby-source-strapi无论如何...

我们开始重构查询,一切似乎都运行良好,直到出现这个问题:

当然 - 所有这些字段都从数据中消失了,所以我无法访问它。

我试图做的是按照警告描述中的说明定义类型。

所以我在 gatsby-node.js 中所做的是这样的:

exports.createSchemaCustomization = ({ actions }) => {
    const { createTypes } = actions
    const typeDefs = `
      type StrapiLandingPages implements Node {
        programmes: [StrapiLandingPagesProgrammes]
      }
      type StrapiLandingPagesProgrammes {
        certification: StrapiLandingPagesProgrammesCertification
      }
      type StrapiLandingPagesProgrammesCertification implements Node @dontInfer {
        id: Int!
        Title: String
        slugUid: String
        sectionTitle: String
        content: String
        published_at: Date @dateformat
        created_at: Date @dateformat
        updated_at: Date @dateformat
      }
    `
    createTypes(typeDefs)
}

但它似乎没有按预期工作。我设法看到了“认证”字段,但其中的所有数据都为空。

知道如何解决这个问题吗?

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Gatsby - webpack 无法使用 `gatsby-plugin-alias-imports`

Gatsby - webpack 无法使用 `gatsby-plugin-alias-imports`

如何解决Gatsby - webpack 无法使用 `gatsby-plugin-alias-imports`

我刚刚创建了一个新的 Gatsby 项目,并创建了几个小组件,它们在导入后显示在索引页面上,如下所示:

  1. import Nav from "../components/Nav"
  2. import Intro from "../components/Intro"
  3. import About from "../components/About"
  4. import Experience from "../components/Experience"
  5. import Projects from "../components/Projects"
  6. import Contact from "../components/Contact"
  7. import Footer from "../components/Footer"

想要稍微整理一下,我发现您可以使用 webpack 定义别名并安装 gatsby-plugin-alias-imports 来实现这一点。使用 yarn add gatsby-plugin-alias-imports 安装插件并添加必要的配置后,我的 gatsby-config.js 如下所示:

  1. const path = require(''path'')
  2. module.exports = {
  3. siteMetadata: {
  4. title: "Site Title",},plugins: [
  5. {
  6. resolve: "gatsby-plugin-alias-imports",options: {
  7. alias: {
  8. ''@components'': path.resolve(__dirname,''src/components''),''@pages'': path.resolve(__dirname,''src/pages''),extensions: [
  9. "js",],}
  10. },...
  11. ...

我的项目结构如下:

  1. .
  2. ├── README.md
  3. ├── gatsby-config.js
  4. ├── package.json
  5. ├── src
  6. ├── components
  7. ├── about.js
  8. ├── contact.js
  9. ├── experience.js
  10. ├── footer.js
  11. ├── intro.js
  12. ├── nav.js
  13. └── projects.js
  14. ├── pages
  15. ├── 404.js
  16. └── index.js
  17. └── scss
  18. └── main.scss
  19. ├── static
  20. └── static
  21. └── icons
  22. ├── github.svg
  23. ├── instagram.svg
  24. └── linkedin-in.svg
  25. └── yarn.lock

然而,每当我尝试在导入中使用 @components 语法时:

  1. import { Nav,Intro,About,Experience,Projects,Contact,Footer } from "@components"

yarn run develop 报告无法解析 @components 别名:

  1. ERROR #98124 WEBPACK
  2. Generating development SSR bundle Failed
  3. Can''t resolve ''@components'' in ''/Users/James/Projects/personal-site/src/pages''
  4. If you''re trying to use a package make sure that ''@components'' is installed. If you''re trying to use a
  5. local file make sure that the path is correct.
  6. File: src/pages/index.js:2:0

我是否遗漏了一些明显的东西?我已经阅读了插件的文档,并且认为我没有遗漏任何内容。我已经对 node_modulesyarn.lock 进行了核试验,但没有成功。

大家有什么建议吗?

解决方法

一位朋友向我指出,我在 index.js 目录中遗漏了一个 src/components/ 页面。

据我了解,每当您设置指向目录的别名时,它实际上都会引用包含在指定目录中的 index.js 文件。

创建文件并重新导出其中的组件后,webpack 不再有任何问题。

我的 src/components/index.js 的内容:

  1. export { default as Nav } from ''./nav'';
  2. export { default as Footer } from ''./footer'';
  3. export { default as About } from ''./about'';
  4. export { default as Contact } from ''./contact'';
  5. export { default as Experience } from ''./experience'';
  6. export { default as Intro } from ''./intro'';
  7. export { default as Projects } from ''./projects'';

Gatsby Develop 工作正常,Gatsby Build 导致 WebpackError: Minified React error #130

Gatsby Develop 工作正常,Gatsby Build 导致 WebpackError: Minified React error #130

如何解决Gatsby Develop 工作正常,Gatsby Build 导致 WebpackError: Minified React error #130?

我正在尝试结合 Gatsby、React 和 Bootstrap 5 开发一个网站。我找到了一个我喜欢使用的包 react-photo-gallery。我让它在开发中工作得很好。我注意到当我运行 gatsby Build 时这个包导致了一个错误。这是产生的错误;

success rewriting compilation hashes - 0.014s
success Writing page-data.json files to public directory - 0.002s - 0/0 0.00/s
success Building HTML renderer - 2.063s

 ERROR 

Page data from page-data.json for the Failed page "/photos/": {
  "componentChunkName": "component---src-pages-photos-js","path": "/photos/","result": {
    "pageContext": {}
  },"staticQueryHashes": []
}

Failed Building static HTML for pages - 0.277s

 ERROR #95313 

Building static HTML Failed for path "/photos/"

See our docs page for more info on this error: https://gatsby.dev/debug-html





  Webpackerror: Minified React error #130; visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=object&args[]= for the full message or use the non-minified dev environment for full errors and add  itional helpful warnings.

  - static-entry.js:286 
    webpack:/the-last-batten/.cache/static-entry.js:286:22


not finished Caching JavaScript and CSS webpack compilation - 2.571s
not finished Caching HTML renderer compilation - 0.305s

如果我点击缩小的反应错误 #130 链接,它会显示;

The full text of the error you just encountered is:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

在继续之前,我无法思考如何解决此问题。我知道它与这个 react-photo-gallery 直接相关,我不知道它是否过时或与某些内容冲突。我在下面提供了我当前的整个版本,希望我能得到一些关于这个错误告诉我什么的指导!谢谢。

github link to my build

根据请求更新,Photos.js:

export const photos = [
  {
    src: "https://source.unsplash.com/2ShvY8Lf6l0/800x599",width: 4,height: 3
  },{
    src: "https://source.unsplash.com/Dm-qxdynoEc/800x799",width: 1,height: 1
  },{
    src: "https://source.unsplash.com/qDkso9nvCg0/600x799",width: 3,height: 4
  },{
    src: "https://source.unsplash.com/iecJiKe_RNg/600x799",{
    src: "https://source.unsplash.com/epcsn8Ed8kY/600x799",{
    src: "https://source.unsplash.com/NQSWvyVRIJk/800x599",{
    src: "https://source.unsplash.com/zh7GEuORbUw/600x799",{
    src: "https://source.unsplash.com/PpOHJezOalU/800x599",{
    src: "https://source.unsplash.com/I1ASdgphUH4/800x599",{
    src: "https://source.unsplash.com/XiDA78wAZVw/600x799",{
    src: "https://source.unsplash.com/x8xJpClTvR0/800x599",{
    src: "https://source.unsplash.com/qGQNmBE7mYw/800x599",{
    src: "https://source.unsplash.com/NuO6iTBkHxE/800x599",{
    src: "https://source.unsplash.com/pF1ug8ysTtY/600x400",{
    src: "https://source.unsplash.com/A-fubu9QJxE/800x533",{
    src: "https://source.unsplash.com/5P91SF0zNsI/740x494",height: 3
  }
];

解决方法

我发现了你的错误(现在链接有效)。您只是在 photos 文件夹下导出 photos.js 对象(在 /pages 中)。

Gatsby bases its routing 使用文件夹结构,因此,当您构建项目时,Gatsby 尝试创建一个 /photos 路由并且它正在查找一个对象(不是 React 组件)并且它失败了。

如果您只是想创建一个对象以在其他地方导入/导出,请将其从 /pages 文件夹中移到其他地方。那应该可以解决您的问题。否则,如果您只是想创建一个 /photos 页面,请创建一个有效的语法。

关于Gatsby + Reach 路由器:控制客户端路由路径的最佳模式路由控制工具的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于'gatsby-source-graphql' 导致加载插件错误引用 'gatsby/graphql' 我将它包含在我的 gatsby-config.js 中,如下所示:但它产生了这个错误:我尝试过的:我使用 gatsby info --clipboard 的环境报告是:有什么想法吗?导致问题的原因如下:、Gatsby (gatsby-source-strapi) - 您的数据问题中存在冲突的字段类型、Gatsby - webpack 无法使用 `gatsby-plugin-alias-imports`、Gatsby Develop 工作正常,Gatsby Build 导致 WebpackError: Minified React error #130等相关知识的信息别忘了在本站进行查找喔。

本文标签: