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-transformer-json crashes when .json file in directory starting with a number

See original GitHub issue

Description

When running gatsby develop if you have the gatsby-transformer-json installed and anywhere in you file system you have a .json file directly inside a directory that starts with a number gatsby will crash with

UNHANDLED REJECTION Syntax Error: Unexpected Int "20"
  GraphQLError: Syntax Error: Unexpected Int "20"
  - TypeMapper.js:113 TypeMapper.createType
    [gatsby-json-crasher]/[graphql-compose]/lib/TypeMapper.js:113:43
  - ObjectTypeComposer.js:80 Function.createTemp
    [gatsby-json-crasher]/[graphql-compose]/lib/ObjectTypeComposer.js:80:28
  - ObjectTypeComposer.js:56 Function.create
    [gatsby-json-crasher]/[graphql-compose]/lib/ObjectTypeComposer.js:56:21
  - index.js:59

Steps to reproduce

add “gatsby-transformer-json” { resolve: gatsby-source-filesystem, options: { path: ${__dirname}/src/assets, }, }, to your gatsby-config.js

create a directory called 20m in your src/assets directory create a file called test.json in your src/assets/20m directory with the contents

{
"test":"crash time"
}

Repro Project

Expected result

Json Data should be added to the system

Actual result

gatsby develop crashes:

UNHANDLED REJECTION Syntax Error: Unexpected Int "20"
  GraphQLError: Syntax Error: Unexpected Int "20"
  - TypeMapper.js:113 TypeMapper.createType
    [gatsby-json-crasher]/[graphql-compose]/lib/TypeMapper.js:113:43

Environment

System: OS: Windows 10 10.0.17763 CPU: (16) x64 AMD Ryzen 7 1800X Eight-Core Processor
Binaries: Node: 12.14.0 - C:\Program Files\nodejs\node.EXE npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 44.17763.831.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
wuntuskcommented, Feb 27, 2020

@vladar Agreed that does allow someone to deal with invalid folder names. To verify I dropped this function in which allowed everything to build fine.

    {
      resolve: `gatsby-transformer-json`,
      options: {
        typeName: ({ node, object, isArray }) => {
          const oldName = _.upperFirst(
            _.camelCase(`${path.basename(node.dir)} Json`)
          );

          const newName = `x${oldName}`;  // just add x to every node
          console.log(`${oldName} => ${newName}`);
          return newName;
        },
      },
    }

That being said it’d still be great to give a better error message than

UNHANDLED REJECTION Syntax Error: Unexpected Int “20”

I don’t think that error message is going to lead most people to quickly figure out what’s wrong. It probably also wouldn’t hurt to drop some info on the gatsby-transformer-json plugin doc about this situation. But that probably belongs in another issue?

0reactions
LekoArtscommented, May 7, 2021

Closing this as stale since in the meantime Gatsby v3 and updated related packages were released. Please try with the latest versions and if you still see this problem open a new bug report (it must include a minimal reproduction).

Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-transformer-json
gatsby-transformer-json. Parses raw JSON strings into JavaScript objects e.g. from JSON files. Supports arrays of objects and single objects.
Read more >
android - App crashing when attempting to Write to .json
I created the file in a assets folder but the app is Still exhibiting the same result of closing on me, as with...
Read more >
Sourcing local .json files with Gatsby - Paul Scanlon
Hi all, I recently had a discussion with Rahul on Twitter regarding building a Gatsby blog using only locally sourced .json files…
Read more >
Reading a large JSON file make Julia crashing - Data
I'm trying to read and select a subset of a large JSON file from here. ... the events.zip file is in the tmp...
Read more >
Read/Write JSON Files with Node.js | heynode.com
To prevent crashing we wrap JSON.parse in a try catch statement to gracefully catch any errors. This example shows reading and parsing a...
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