plugins - “gatsby-source-graphql”导致加载插件错误引用“gatsby/graphql”
问题描述
我有一个正在添加的 Gatsby 安装,但是,在尝试构建一些graphQL 构建时数据获取时,我遇到了一个在运行npm start (gatsby develop)或gatsby build时导致错误的问题.
我安装了gatsby-source-graphql,如下所述: https ://www.npmjs.com/package/gatsby-source-graphql
我将它包含在我的gatsby-config.js中,如下所示:
module.exports = {
// Optional
siteMetadata: {
title: `Title from siteMetadata`,
},
plugins: [
{
resolve: `gatsby-plugin-manifest`,
options: {
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)
// see https://developers.google.com/web/fundamentals/web-app-manifest/#display
display: "standalone",
icon: "src/images/icon.png", // This path is relative to the root of the site.
// An optional attribute which provides support for CORS check.
// If you do not provide a crossOrigin option, it will skip CORS for manifest.
// Any invalid keyword or empty string defaults to `anonymous`
crossOrigin: `use-credentials`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
// GraphQL APIs for use during build-time.
// https://www.npmjs.com/package/gatsby-source-graphql
//////////////////////////////////////////////////////
{
resolve: "gatsby-source-graphql",
options: {
// Arbitrary name for the remote schema Query type
typeName: "SpaceX",
// Field under which the remote schema will be accessible. You'll use this in your Gatsby query
fieldName: "spaceX",
// Url to query from
url: "https://api.spacex.land/graphql/",
},
},
// {
// resolve: "gatsby-source-graphql",
// options: {
// // Arbitrary name for the remote schema Query type
// typeName: "SWAPI",
// // Field under which the remote schema will be accessible. You'll use this in your Gatsby query
// fieldName: "swapi",
// // Url to query from
// url: "https://swapi-graphql.netlify.app/.netlify/functions/index",
// },
// },
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
`gatsby-plugin-react-helmet`,
`gatsby-theme-material-ui`,
{
resolve: `gatsby-plugin-nprogress`,
options: {
// Setting a color is optional.
color: `tomato`,
// Disable the loading spinner.
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)
],
}
但它会产生这个错误:
Error in "/Users//Documents/projects/project/node_modules/gatsby-source-graphql/gatsby-node.js":
Cannot find module 'gatsby/graphql'
Error: Cannot find module 'gatsby/graphql'
- loader.js:636 Function.Module._resolveFilename
internal/modules/cjs/loader.js:636:15
- loader.js:562 Function.Module._load
internal/modules/cjs/loader.js:562:25
- loader.js:692 Module.require
internal/modules/cjs/loader.js:692:17
- v8-compile-cache.js:159 require
[client]/[v8-compile-cache]/v8-compile-cache.js:159:20
- gatsby-node.js:8 Object.<anonymous>
[tbwa-project-template]/[gatsby-source-graphql]/gatsby-node.js:8:5
- v8-compile-cache.js:178 Module._compile
[client]/[v8-compile-cache]/v8-compile-cache.js:178:30
- loader.js:789 Object.Module._extensions..js
internal/modules/cjs/loader.js:789:10
- loader.js:653 Module.load
internal/modules/cjs/loader.js:653:32
- loader.js:593 tryModuleLoad
internal/modules/cjs/loader.js:593:12
- loader.js:585 Function.Module._load
internal/modules/cjs/loader.js:585:3
- loader.js:692 Module.require
internal/modules/cjs/loader.js:692:17
- v8-compile-cache.js:159 require
[client]/[v8-compile-cache]/v8-compile-cache.js:159:20
- resolve-module-exports.ts:197 resolveModuleExports
[client]/[gatsby]/src/bootstrap/resolve-module-exports.ts:197:26
- validate.ts:348 forEach
[client]/[gatsby]/src/bootstrap/load-plugins/validate.ts:348:31
- Array.forEach
- validate.ts:340 collatePluginAPIs
[client]/[gatsby]/src/bootstrap/load-plugins/validate.ts:340:20
not finished load plugins - 0.727s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project-template@1.0.0 start: `gatsby develop`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project-template@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/_logs/2021-02-04T00_31_34_070Z-debug.log
我试过的:
我在配置中尝试了两种不同的 gatsby-source-graphql 定义(一次只有一个),但都产生了错误。第二个(上面注释掉的)直接取自github 页面示例和Gatsby 示例。
我尝试更改插件的顺序(我尝试了每个位置)但仍然出现错误。
如果我在配置中评论任何和所有 gatsby-source-graphql 部分,它不会产生错误。
如果我注释掉除gatsby-source-graphql 部分之一之外的所有插件,我仍然会得到完全相同的错误。
我还尝试删除 node_modules 文件夹,运行 npm run clean,然后再次 npm install 没有任何变化。
我也尝试了以下链接中描述的 DanceParty 解决方案,没有任何变化: https ://github.com/gatsbyjs/gatsby/issues/8249
我试过跑步
npm update
,npm install npm@latest -g
并没有看到任何变化。
我使用gatsby info --clipboard的环境报告是:
System:
OS: macOS 10.15.7
CPU: (4) x64 Intel(R) Core(TM) i5-6287U CPU @ 3.10GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.23.1 - /usr/local/bin/node
npm: 6.14.10 - /usr/local/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 88.0.4324.96
Firefox: 85.0
Safari: 14.0.2
npmPackages:
gatsby: ^2.26.1 => 2.32.0
gatsby-image: ^2.10.0 => 2.11.0
gatsby-plugin-layout: ^1.9.0 => 1.10.0
gatsby-plugin-manifest: ^2.11.0 => 2.12.0
gatsby-plugin-material-ui: ^2.1.10 => 2.1.10
gatsby-plugin-nprogress: ^2.9.0 => 2.10.0
gatsby-plugin-react-helmet: ^3.8.0 => 3.10.0
gatsby-plugin-sharp: ^2.13.0 => 2.14.0
gatsby-plugin-transition-link: ^1.20.5 => 1.20.5
gatsby-source-filesystem: ^2.10.0 => 2.11.0
gatsby-theme-material-ui: ^1.0.13 => 1.0.13
gatsby-transformer-sharp: ^2.11.0 => 2.12.0
npmGlobalPackages:
gatsby-cli: 2.19.0
有任何想法吗?
解决方案
我开始创建一个最小的复制品并将所有内容一个一个地添加回来,但我决定在我的第一个设置中玩更多的东西......我很高兴我做到了。
以下是导致问题的原因:
这个 Gatsby 安装是我们使用的项目模板的一部分,其中包括后端代码、前端、管道部署脚本等。结构类似于:
项目模板文件夹
- 客户文件夹
- 服务器文件夹
- 其他文件夹
Gatsby 安装在客户端文件夹中,但有时我需要进入根文件夹来执行某些操作。
所以发生了什么事!?我不小心安装gatsby-source-graphql
到根文件夹而不是客户端文件夹中。就这样。我应该在跑步时捡起它,gatsby info --clipboard
因为它显然没有被列为依赖项。
推荐阅读
- python - 包含已删除元素的列表
- prometheus - 有没有办法让 prometheus 不刮掉 pod 的端口?
- python - 对于每一行,获取最频繁值的频率
- c# - 如何在 C# 中验证签名而不通过填充算法
- html - 如何在由宽度定义的元素下响应式放置 Div
- javascript - 未捕获的语法错误:意外的标识符 game.js:25
- jackson - 如何在 Ktor 中配置 jackson-modules-java8
- wordpress - wordpress 下一篇文章链接没有按预期工作
- sql - 在一个查询中使用两次嵌套查询 - 用于 FROM 和 WHERE
- java - 界面管理eclipse