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

Uncaught TypeError: Cannot read property 'call' of undefined #2804

Closed
patreeceeo opened this issue Nov 5, 2017 · 8 comments
Closed

Uncaught TypeError: Cannot read property 'call' of undefined #2804

patreeceeo opened this issue Nov 5, 2017 · 8 comments

Comments

@patreeceeo
Copy link

patreeceeo commented Nov 5, 2017

Gatsby CLI version 1.1.19
Node version 8.6.0
macOS 10.12.6

gatsby-config.js

module.exports = {
    siteMetadata: {
        title: `Personal site of Patrick Canfield`,
        description: `The best site on the interwebs`,
        siteUrl: `https://patrickcanfield.com`
    },
    plugins: [
        {
            resolve: `gatsby-plugin-feed`,
            options: {
                query: `
                    {
                      site {
                        siteMetadata {
                          title
                          description
                          siteUrl
                          site_url: siteUrl
                        }
                      }
                    }
                `,
                feeds: [
                    {
                        serialize: ({ query: { site, allMarkdownRemark } }) => {
                            return allMarkdownRemark.edges.map(edge => {
                                return Object.assign({}, edge.node.frontmatter, {
                                    description: edge.node.excerpt,
                                    url: site.siteMetadata.siteUrl + edge.node.frontmatter.path,
                                    guid: site.siteMetadata.siteUrl + edge.node.frontmatter.path,
                                    custom_elements: [{ 'content:encoded': edge.node.html }],
                                });
                            });
                        },
                        query: `
                            {
                              allMarkdownRemark(
                                limit: 1000,
                                sort: { order: DESC, fields: [frontmatter___date] },
                              ) {
                                edges {
                                  node {
                                    excerpt
                                    html
                                    frontmatter {
                                      title
                                      date
                                      path
                                    }
                                  }
                                }
                              }
                            }
                          `,
                        output: '/rss.xml',
                        feedTitle: 'Blog of Patrick Canfield'
                    }
                ]
            }
        },
        {
            resolve: `gatsby-plugin-typography`,
            options: {
                pathToConfigModule: `src/utils/typography.js`,
            },
        },
        {
            resolve: `gatsby-source-filesystem`,
            options: {
                path: `${__dirname}/src/blog`,
                name: 'pages',
            },
        },
        {
            resolve: 'gatsby-transformer-remark',
            options: {
                plugins: [
                    `gatsby-remark-smartypants`,
                    {
                        resolve: `gatsby-remark-images`,
                        options: {
                            // It's important to specify the maxWidth (in pixels) of
                            // the content container as this plugin uses this as the
                            // base for generating different widths of each image.
                            maxWidth: 800,
                            // Remove the default behavior of adding a link to each
                            // image.
                            // linkImagesToOriginal: false,
                        },
                    },
                    {
                        resolve: 'gatsby-remark-copy-linked-files',
                        options: {
                            // `ignoreFileExtensions` defaults to [`png`, `jpg`, `jpeg`, `bmp`, `tiff`]
                            // as we assume you'll use gatsby-remark-images to handle
                            // images in markdown as it automatically creates responsive
                            // versions of images.
                            //
                            // If you'd like to not use gatsby-remark-images and just copy your
                            // original images to the public directory, set
                            // `ignoreFileExtensions` to an empty array.
                            ignoreFileExtensions: [],
                        },
                    }
                ]
            }
        },
        {
            resolve: `gatsby-plugin-google-analytics`,
            options: {
                trackingId: '<ID>',
                // Setting this parameter is optional
                // anonymize: true
            },
        },
    ],
};

package.json

{
  "name": "gatsby-starter-default",
  "description": "Gatsby default starter",
  "version": "1.0.0",
  "author": "Kyle Mathews <[email protected]>",
  "dependencies": {
    "gatsby": "^1.9.100",
    "gatsby-cli": "^1.1.19",
    "gatsby-link": "^1.6.22",
    "gatsby-plugin-feed": "^1.3.11",
    "gatsby-plugin-google-analytics": "^1.0.11",
    "gatsby-plugin-react-helmet": "^1.0.8",
    "gatsby-plugin-sharp": "^1.6.15",
    "gatsby-plugin-typography": "^1.7.10",
    "gatsby-remark-copy-linked-files": "^1.5.15",
    "gatsby-remark-images": "^1.5.26",
    "gatsby-remark-smartypants": "^1.4.8",
    "gatsby-source-filesystem": "^1.5.5",
    "gatsby-transformer-remark": "^1.7.18",
    "typography-theme-lawton": "^0.15.10"
  },
  "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.7.4"
  }
}

When I click a link made using the Link component from gatsby-link that leads back to my site index I get this error and the index page doesn't load. However if you click the link again it works.

TypeError: Cannot read property 'call' of undefined
    at t (https://patrickcanfield.com/commons-b300071e3db7b0a0e680.js:1:107)
    at https://patrickcanfield.com/app-d05d87c84f46f8ca5694.js:1:28566
    at https://patrickcanfield.com/app-d05d87c84f46f8ca5694.js:1:12050
    at https://patrickcanfield.com/app-d05d87c84f46f8ca5694.js:1:11940
    at https://patrickcanfield.com/app-d05d87c84f46f8ca5694.js:1:28541
    at s (https://patrickcanfield.com/app-d05d87c84f46f8ca5694.js:1:3280)
    at https://patrickcanfield.com/app-d05d87c84f46f8ca5694.js:1:3380
    at window.webpackJsonp (https://patrickcanfield.com/commons-b300071e3db7b0a0e680.js:1:396)
    at https://patrickcanfield.com/component---src-pages-index-js-e15e3a957a02c2a4793f.js:1:1

For now I've created this workaround which devolves pushState to a regular location change with full reload:

if(window.location.host === "patrickcanfield.com") {
    window.history.pushState = (stateObj, name, url) => {
        window.location.path = url;
    };
}
@KyleAMathews
Copy link
Contributor

Seems like there's a JS error in your code? This doesn't happen with vanilla Gatsby.

@patreeceeo
Copy link
Author

It seemed to be happening in Gatsby generated code. Its not happening anymore so I'll close this issue and reopen if I see it again.

@danoc
Copy link
Contributor

danoc commented Nov 7, 2017

@pzatrick I just started seeing the same issue. Has it come back by chance?

It happens (seemingly) randomly when clicking on Link after doing gatsby build --prefix-paths. Sometimes it happens after 4 clicks, sometimes 10. And it's not always the same links that can throw this error. (FWIW, they all share the same template.)

When I get the error, this is the order of errors:

  1. JS errors and says a Webpack module is missing.
    image
  2. Immediately get another error saying Graphql's data is undefined.
  3. All subsequent link clicks throw the following error:
    image

@danoc
Copy link
Contributor

danoc commented Nov 7, 2017

When I look up the missing module id, it seems to trace back to lodash. 🤔

Edit: I'll continue digging in and post here if I find anything.

@danoc
Copy link
Contributor

danoc commented Nov 7, 2017

This issue may be a duplicate of #1043.

@buildtheui
Copy link

@danoc did you find any fix?

@danoc
Copy link
Contributor

danoc commented Feb 9, 2018

@whispers16 – I think it eventually started working but I didn't know what the fix was.

My best guess is that it was related to the weird way that I was using the Link package. I was building many different Gatsby sites (different repos) then combining them by copying over the dist folders.

@jeffwillette
Copy link
Contributor

I think (most commonly) it is a file caching issue, I've run into it a few times for a brief stint (see #1043 (comment))

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