gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.2k stars 10.33k forks source link

[gatsby-transformer-react-docgen] - Cannot read property 'internal' of null #4003

Closed derekr closed 6 years ago

derekr commented 6 years ago

Description

When using gatsby-transformer-react-docgen I get an error UNHANDLED REJECTION error during the source and transform stage.

Environment

Gatsby version: ^1.9.158 Node.js version: v9.5.0 Operating System: OSX 10.13.3

File contents (if changed):

gatsby-config.js:

module.exports = {
  siteMetadata: {
    title: 'Gatsby Default Starter',
  },
  plugins: [
    'gatsby-plugin-react-helmet',
    'gatsby-transformer-react-docgen',
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `components`,
        path: `${__dirname}/src/components/`,
      },
    },
  ],
};

package.json:

{
  "name": "gatsby-starter-default",
  "description": "Gatsby default starter",
  "version": "1.0.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "gatsby": "^1.9.158",
    "gatsby-link": "^1.6.34",
    "gatsby-plugin-react-helmet": "^2.0.3",
    "gatsby-source-filesystem": "^1.5.19",
    "gatsby-transformer-react-docgen": "^1.0.13",
    "react-helmet": "^5.2.0"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "main": "n/a",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --trailing-comma es5 --no-semi --single-quote --write \"src/**/*.js\"",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {
    "prettier": "^1.10.2"
  }
}

gatsby-node.js: not changed gatsby-browser.js: not changed gatsby-ssr.js: not changed

Actual result

docgen ☭ npx gatsby develop                                                                    
success delete html files from previous builds — 0.007 s
success open and validate gatsby-config.js — 0.004 s
success copy gatsby files — 0.018 s
success onPreBootstrap — 0.004 s
success source and transform nodes — 0.086 s
error UNHANDLED REJECTION

  TypeError: Cannot read property 'internal' of null

  - infer-graphql-input-fields.js:222 
    [docgen]/[gatsby]/dist/schema/infer-graphql-input-fields.js:222:38

  - lodash.js:4917 
    [docgen]/[lodash]/lodash.js:4917:15

  - lodash.js:3002 baseForOwn
    [docgen]/[lodash]/lodash.js:3002:24

  - lodash.js:4886 
    [docgen]/[lodash]/lodash.js:4886:18

  - lodash.js:9334 Function.forEach
    [docgen]/[lodash]/lodash.js:9334:14

  - infer-graphql-input-fields.js:209 inferInputObjectStructureFromNodes
    [docgen]/[gatsby]/dist/schema/infer-graphql-input-fields.js:209:5

  - build-node-types.js:88 _callee$
    [docgen]/[gatsby]/dist/schema/build-node-types.js:88:36

  - next_tick.js:150 process._tickCallback
    internal/process/next_tick.js:150:11

Expected behavior

Development server starts and I can query as expected for the react docgen transformer.

Steps to reproduce

gatsby new docgen
cd docgen
yarn add gatsby-source-filesystem gatsby-transformer-react-docgen
npm gatsby develop
m-allanson commented 6 years ago

I was able to recreate this issue from @derekr's report above. I thought maybe the plugin was failing due to there being no docgen blocks, but adding a docblock to the src/components/Header component doesn't make any difference to the console output.

Ah! I was about to pass on this, but it looks like the build will work as long as one of your components has some PropTypes defined. I can see this would be a pretty frustrating problem..

@KyleAMathews or @jquense is it possible to add some logging around this?

derekr commented 6 years ago

Thanks for following up @m-allanson! Confirmed the propTypes work around. Some logging would be rad. I could take a look at it some time next week if no one hops on it.

KyleAMathews commented 6 years ago

Huh weird. Yeah, we should either log and/or just work around the lack of data from not having propTypes

pieh commented 6 years ago

As this is graphql schema related I will have a look. Is there fast way to reproduce it?

trickydisco78 commented 6 years ago

I'm getting the exact same error using the datocms-source plugin

https://github.com/datocms/gatsby-source-datocms/issues/11

Have cloned their portfolio repo and getting the same error

added proptypes to the header component but doesn't work :(

KyleAMathews commented 6 years ago

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!