Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev server crashes often with error: Cannot read property 'id' of undefined #4162

Closed
jeffwillette opened this issue Feb 21, 2018 · 10 comments
Closed
Assignees

Comments

@jeffwillette
Copy link
Contributor

Description

I get constant failures of the dev server with the error Cannot read property 'id' of undefined. I believe this is caused in part because vim is deleting and adding a file probably after some plugin is making a buffer change and remaking the file...I am not sure exactly as I have not been able to exactly reproduce it in a starter yet.

Environment

Gatsby version: 1.1.41
Node.js version: v9.5.0
Operating System: OSSierra 10.13.3

File contents (if changed):

gatsby-config.js:
package.json:
gatsby-node.js:
gatsby-browser.js:
gatsby-ssr.js:

Actual result

 WAIT  Compiling...                                                                                                                           1:02:04 PM

 DONE  Compiled successfully in 549ms                                                                                                         1:02:05 PM

info file deleted at /Users/Jeff/go/src/github.com/deltaskelta/interviews/frontend/src/pages/login.js
info added file at /Users/Jeff/go/src/github.com/deltaskelta/interviews/frontend/src/pages/login.js~
error UNHANDLED REJECTION


  TypeError: Cannot read property 'id' of undefined

  - page-query-runner.js:182
    [frontend]/[gatsby]/dist/internal-plugins/query-runner/page-query-runner.js:182:75

  - Array.reduce

  - page-query-runner.js:178 findDirtyIds
    [frontend]/[gatsby]/dist/internal-plugins/query-runner/page-query-runner.js:178:18

  - page-query-runner.js:102 _callee2$
    [frontend]/[gatsby]/dist/internal-plugins/query-runner/page-query-runner.js:102:37

  - page-query-runner.js:122 runQueuedActions
    [frontend]/[gatsby]/dist/internal-plugins/query-runner/page-query-runner.js:122:18

  - mitt.js:1
    [frontend]/[mitt]/dist/mitt.js:1:268

  - Array.map

  - mitt.js:1 Object.emit
    [frontend]/[mitt]/dist/mitt.js:1:252

  - api-runner-node.js:201
    [frontend]/[gatsby]/dist/utils/api-runner-node.js:201:27


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected behavior

Dev server should not crash

Steps to reproduce

I haven't been able to reliably reproduce yet, will add steps when I can narrow it down, posting for ideas based on the error output in the meantime

1.

2.

3.

...

@HighTide2020
Copy link

I tried this a few times and couldn’t reproduce ****

Not that this is a fix.But it could help isolate the issue Have you tried changing the script to NPM run dev or Yarn start. That way if those work you can isolate the bug to the Gatsby CLI. Which you should uninstall and reinstall again anyways Before using again. Or my Next thought would bebecause it is happening when Webpack is bunbkeing the JS it lookings like. it mite be your Webpack layout if there is one in Gatsby node

Also are you p

@KyleAMathews
Copy link
Contributor

I added a check to the code there to make sure that the node still exists before trying to access the id off it. Will merge and release it once Travis finishes. Lemme know if you have any more trouble after upgrading!

@ghost ghost removed the review label Feb 21, 2018
@jeffwillette
Copy link
Contributor Author

cool, thanks for the quick fix, haven't had a problem since the update

@jeffwillette
Copy link
Contributor Author

@KyleAMathews this fix took care of about 70% of the crashes, but it still does crash sometimes with the same error. Would you like me to open up a new issue or reopen this one? or can nothing else be done about it

@KyleAMathews
Copy link
Contributor

@deltaskelta hmmm bummer. We can keep the same issue going.

Is it the exact same error though? Or is the stack trace different?

@KyleAMathews KyleAMathews reopened this Feb 23, 2018
@jeffwillette
Copy link
Contributor Author

jeffwillette commented Feb 23, 2018

Here is the trace, looks like it was coming from my gatsby-node this time

EDIT: I have no idea what my gatsby-node looked like when that happened because it was quite a while ago but I can check if and when it happens again

info file deleted at /Users/Jeff/go/src/github.com/deltaskelta/interviews/frontend/src/pages/about/index.js
info added file at /Users/Jeff/go/src/github.com/deltaskelta/interviews/frontend/src/pages/about/index.js~
error ENOENT: no such file or directory, open '/Users/Jeff/go/src/github.com/deltaskelta/interviews/frontend/src/pages/about/index.js~'


  Error: ENOENT: no such file or directory, open '/Users/Jeff/go/src/github.com/deltaskelta/interviews/frontend/src/pages/about/index.js~'

info added file at /Users/Jeff/go/src/github.com/deltaskelta/interviews/frontend/src/pages/about/index.js
info file deleted at /Users/Jeff/go/src/github.com/deltaskelta/interviews/frontend/src/pages/about/index.js~
error UNHANDLED EXCEPTION


  TypeError: Cannot read property 'id' of undefined

  - gatsby-node.js:79 FSWatcher.<anonymous>
    [frontend]/[gatsby-source-filesystem]/gatsby-node.js:79:21

  - index.js:196 FSWatcher.<anonymous>
    [frontend]/[chokidar]/index.js:196:15

  - index.js:238 FSWatcher._emit
    [frontend]/[chokidar]/index.js:238:5

  - index.js:555 FSWatcher._remove
    [frontend]/[chokidar]/index.js:555:50

  - fsevents-handler.js:185 FSWatcher.<anonymous>
    [frontend]/[chokidar]/lib/fsevents-handler.js:185:16

  - fsevents-handler.js:216
    [frontend]/[chokidar]/lib/fsevents-handler.js:216:11

@KyleAMathews
Copy link
Contributor

Ok, added another PR that follows up on some work I did yesterday + adds a fix for the above issue #4209

@jeffwillette
Copy link
Contributor Author

This crash happened very sporadically so I will close and assume it is fixed for now

@Undistraction
Copy link
Contributor

Undistraction commented May 3, 2018

I'm getting a similar (intermittent) error which happens at the end of the build:

The GraphQL query from .../src/components/templates/article.js failed

Errors:
  GraphQLError: Cannot read property 'id' of undefined

Query:
query ArticleQuery(
  $slug: String
  $previousSlug: String
  $nextSlug: String
  $dateFormat: String
) {
  markdownRemark(fields: {slug: {eq: $slug}}) {
    html
    frontmatter {
      title
      date(formatString: $dateFormat)
      keywords
      image {
        childImageSharp {
          sizes {
            ...GatsbyImageSharpSizes
          }
        }
      }
    }
    fields {
      tags
      metadata {
        description
        title
        keywords
      }
    }
  }
  previous: markdownRemark(fields: {type: {eq: "article"}, slug: {eq: $previousSlug}}) {
    id
    frontmatter {
      title
    }
    fields {
      slug
    }
  }
  next: markdownRemark(fields: {type: {eq: "article"}, slug: {eq: $nextSlug}}) {
    frontmatter {
      title
    }
    fields {
      slug
    }
  }
}

fragment GatsbyImageSharpSizes on ImageSharpSizes {
  base64
  aspectRatio
  src
  srcSet
  sizes
}

"gatsby": "^1.9.131",

It's intermittent but I'm convinced it's related to the cache. Deleting the cache and rebuilding sometimes fixes it. The strange thing is that the site actually builds perfectly despite the error.

Should I open a new issue?

@m-allanson
Copy link
Contributor

Can you try updating to the latest version of Gatsby? If that doesn't work, then open a new issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants