question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gatsby config validation should suggest related keys

See original GitHub issue

Summary

When running a gatsby site the gatsby-config is validated. The error message is quite long due to multiple instances of the failed validation error that appear after the initial ValidationError. The error also doesn’t suggest any possible mis-spellings, so a user new to Gatsby can become frustrated fairly easily, not knowing that plugin should be plugins.

full error log
➜ yarn workspace scotchy-site develop
yarn workspace v1.13.0
yarn run v1.13.0
$ gatsby develop
⠁ The site's gatsby-config.js failed validation
ValidationError: "plugin" is not allowed
error The site's gatsby-config.js failed validation


  Error: The site's gatsby-config.js failed validation

  - config.js:29 module.exports
    [Scotch-gastby-theme-demo]/[gatsby]/dist/redux/reducers/config.js:29:17

  - redux.js:451 combination
    [Scotch-gastby-theme-demo]/[redux]/lib/redux.js:451:29

  - redux.js:211 dispatch
    [Scotch-gastby-theme-demo]/[redux]/lib/redux.js:211:22

  - index.js:89 Object.action [as dispatch]
    [Scotch-gastby-theme-demo]/[gatsby]/dist/redux/index.js:89:91

  - index.js:117
    [Scotch-gastby-theme-demo]/[gatsby]/dist/bootstrap/index.js:117:11

  - Generator.next

  - util.js:16 tryCatcher
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/util.js:16:23

  - promise.js:512 Promise._settlePromiseFromHandler
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:512:31

  - promise.js:569 Promise._settlePromise
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:569:18

  - promise.js:614 Promise._settlePromise0
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:614:10

  - promise.js:694 Promise._settlePromises
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:694:18

  - promise.js:638 Promise._fulfill
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:638:18

  - promise.js:432 Promise._resolveCallback
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:432:57

  - promise.js:524 Promise._settlePromiseFromHandler
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:524:17


error UNHANDLED REJECTION


  Error: The site's gatsby-config.js failed validation

  - config.js:29 module.exports
    [Scotch-gastby-theme-demo]/[gatsby]/dist/redux/reducers/config.js:29:17

  - redux.js:451 combination
    [Scotch-gastby-theme-demo]/[redux]/lib/redux.js:451:29

  - redux.js:211 dispatch
    [Scotch-gastby-theme-demo]/[redux]/lib/redux.js:211:22

  - index.js:89 Object.action [as dispatch]
    [Scotch-gastby-theme-demo]/[gatsby]/dist/redux/index.js:89:91

  - index.js:117
    [Scotch-gastby-theme-demo]/[gatsby]/dist/bootstrap/index.js:117:11

  - Generator.next

  - util.js:16 tryCatcher
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/util.js:16:23

  - promise.js:512 Promise._settlePromiseFromHandler
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:512:31

  - promise.js:569 Promise._settlePromise
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:569:18

  - promise.js:614 Promise._settlePromise0
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:614:10

  - promise.js:694 Promise._settlePromises
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:694:18

  - promise.js:638 Promise._fulfill
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:638:18

  - promise.js:432 Promise._resolveCallback
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:432:57

  - promise.js:524 Promise._settlePromiseFromHandler
    [Scotch-gastby-theme-demo]/[bluebird]/js/release/promise.js:524:17


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /Users/chris/.nvm/versions/node/v10.6.0/bin/node
Arguments: /usr/local/Cellar/yarn/1.13.0/libexec/lib/cli.js develop
Directory: /Users/chris/tmp/Scotch-gastby-theme-demo/site
Output:

Basic example

I’d like to see the output truncated to exclude the duplicate errors and also add a suggested option based on Levenshtein distance to possible valid keys.

➜ yarn workspace scotchy-site develop
yarn workspace v1.13.0
yarn run v1.13.0
$ gatsby develop
⠁ The site's gatsby-config.js failed validation
ValidationError: the key "plugin" is not allowed, did you mean "plugins"?

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /Users/chris/.nvm/versions/node/v10.6.0/bin/node
Arguments: /usr/local/Cellar/yarn/1.13.0/libexec/lib/cli.js develop
Directory: /Users/chris/tmp/Scotch-gastby-theme-demo/site
Output:

Motivation

Why are we doing this? What use cases does it support? What is the expected outcome?

This change supports people new to Gatsby and new to reading error messages in general by showing less “noise” and providing helpful suggestions, making Gatsby an even friendlier tool for newcomers.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:21 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
DZuz14commented, Mar 31, 2020

@DSchau Im going to work on this. I’ve been doing some snooping around and is this where we should be doing the check?

https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/bootstrap/load-plugins/index.js

Perhaps test the flattened array for the typos before it goes any further and tries to load any of the plugins via the load.js file?

1reaction
jlengstorfcommented, May 29, 2019

It looks like we’ve started some of this work here: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-cli/src/did-you-mean.js

So that’s probably the best place to start. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby Config API
The configuration file should export a JavaScript object. ... Here's an example showing how to write an object with keys to resolve the...
Read more >
How to validate config options for a Gatsby Plugin?
As a Gatsby Plugin author, I want to apply some validations, e.g. the gatsby-config needs to include a requestor key-value pair for my ......
Read more >
Gatsby Changelog | 5.3.0
By using a new <Slice /> React component in combination with a src/slices directory or createSlice API for common UI features, Gatsby will...
Read more >
How to Secure GatsbyJS Sites with Auth0 for Authentication
Add Gatsby Auth env config. While you could manually update the variables AUTH0_DOMAIN , AUTH0_CLIENTID , and AUTH0_CALLBACK , it's a ...
Read more >
Generate an SEO-Friendly Sitemap for your Gatsby Site
Querying data with GraphQL. Inside our gatsby-config.js , we can write a GraphQL query to pull whatever data we need: js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found