gatsby: Unhandled Rejection (SyntaxError): Unexpected token < in JSON at position 0

Description

Since updating gatsby to latest version i’ve been getting the following error in development.

Unhandled Rejection (SyntaxError): Unexpected token < in JSON at position 0

Steps to reproduce

gatsby develop

Expected result

no error

Actual result

XMLHttpRequest.request.onreadystatechange
/Users/admin/Desktop/Projects/webpack/bootstrap:52
  49 | } else {
  50 | 	// success
  51 | 	try {
> 52 | 		var update = JSON.parse(request.responseText);
  53 | 	} catch (e) {
  54 | 		reject(e);
  55 | 		return;
View compiled
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.

Environment

Binaries: Node: 11.6.0 - /usr/local/bin/node Yarn: 1.13.0 - /usr/local/bin/yarn npm: 6.7.0 - /usr/local/bin/npm Languages: Python: 2.7.10 - /usr/bin/python Browsers: Chrome: 72.0.3626.81 Safari: 12.0.2 npmPackages: gatsby: ^2.0.111 => 2.0.111 gatsby-cli: ^2.4.8 => 2.4.8 gatsby-image: ^2.0.29 => 2.0.29 gatsby-plugin-emotion: ^4.0.3 => 4.0.3 gatsby-plugin-feed: ^2.0.13 => 2.0.13 gatsby-plugin-google-analytics: ^2.0.13 => 2.0.13 gatsby-plugin-less: ^2.0.11 => 2.0.11 gatsby-plugin-lodash: ^3.0.4 => 3.0.4 gatsby-plugin-mailchimp: ^4.0.0 => 4.0.0 gatsby-plugin-manifest: ^2.0.17 => 2.0.17 gatsby-plugin-netlify: ^2.0.8 => 2.0.8 gatsby-plugin-offline: ^2.0.22 => 2.0.22 gatsby-plugin-react-helmet: ^3.0.6 => 3.0.6 gatsby-plugin-sharp: ^2.0.20 => 2.0.20 gatsby-plugin-sitemap: ^2.0.5 => 2.0.5 gatsby-plugin-typography: ^2.2.7 => 2.2.7 gatsby-remark-images: ^3.0.3 => 3.0.3 gatsby-source-filesystem: ^2.0.20 => 2.0.20 gatsby-source-firestore: ^1.0.3 => 1.0.3 gatsby-transformer-json: ^2.1.8 => 2.1.8 gatsby-transformer-remark: ^2.2.3 => 2.2.3 gatsby-transformer-sharp: ^2.1.13 => 2.1.13 npmGlobalPackages: gatsby-cli: 2.4.8

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 26 (11 by maintainers)

Most upvoted comments

I had the same issue when I started adding plugins configuration to gatsby-config.js. I mixed string declaration with object, which caused the issues

plugins: [
  {
    resolve: `gatsby-plugin-sass`,
    options: {
      precision: 8,
    },
  },
  `gatsby-plugin-react-helmet`
]

when it should be:

plugins: [
  {
    resolve: `gatsby-plugin-sass`,
    options: {
      precision: 8,
    },
  },
  {
    resolve: `gatsby-plugin-react-helmet`
  }
]

Ran into this issue today - @adamfaryna suggestions worked for me.

`gatsby-plugin-styled-components`

changed to

{
  resolve: `gatsby-plugin-styled-components`,
},

solved the issue for me.

EDIT: this error still appears occasionally for me on yarn start after changing the gatsby-config.js file.

Just ran into the same issue. Like @adamfaryna I was also mixing string and object declaration in gatsby-config.js

Updating my declarations to be consistent seems to have resolved the problem.

Seeing this too almost every time I restart the dev server manually but I just need to refresh the page manually too to make it disappear. If I can pinpoint the exact definition of this ‘almost’ I will report back.

I’m seeing this error too in my gatsby-mdx project. Happens occasionally when I run gatsby develop the first time, and then also when renaming/deleting mdx content pages.

@humbertqz unrelated, probably.

That’s triggered by this line because it looks like you’re missing a preceding forward slash? e.g. it should be /plaza-cataluna not plaza-cataluna

Im using gatsby-starter-default in both of my projects and see this error daily.

Thank you Kyle for confirming this!

I’ve been seeing this too just now playing around with gatsby-starter-blog while fixing a delete data hot reload bug — it’s pretty easy to reproduce — just delete and then checkout the delete file (to restore it) a few times and the error happens sooner or later.