gatsby: navigation.js:173 Uncaught TypeError

Still getting this error from links after updating to Gatsby 2.19.12. I’ve checked my dependencies and re-installed node modules.

I can recreate this issue by:

  1. updating this starter
  2. making a new root element implementing the router with ‘/’ corresponding to ‘index.js’, ‘/foo’ corresponding to the blog or some trivial page
  3. putting a new link to the blog or some trivial page onto index.js and clicking it
navigation.js:173 Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
    at navigation.js:173
>  170 | if (document.title) {
>  171 |      pageName = document.title
>  172 | }
>  173 | const pageHeadings = document
>  174 |     .getElementById(`gatsby-focus-wrapper`)
>  175 |     .getElementsByTagName(`h1`)
>  176 | if (pageHeadings && pageHeadings.length) {

See this previously closed issue, seems other people are still running into this aswell

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 20 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@garrison0 what is the file name that you are using for the new page? Are you sure it matches that path that you are linking to? For example, did you make a foo.js and then link to /foo? I found if I make a Foo.js and then link to /foo, I see the error you are seeing

The problem persists for me in my environment.

I’ve deleted both node_modules and package-lock.json, reinstalled, and checked the dependencies. I’ve noticed gatsby-link still requires @reach/router 1.2.6 whereas gatsby requires 1.2.1. I’m not sure how relevant that is because the bug persists whether I important Link from gatsby, gatsby-link, or @reach/router.

Interesting if I build and serve, when I first try to load the link, it works, but afterwards I get the error in the devtools console.

If there’s any other information I could provide, I’d be happy to

@arun-is

that fixed the problem, thanks

but why wouldn’t something like this work? :

...
import NewPage from './NewPage.js'

const App = () => (
    <Router>
      <Home path="/" />
      <NewPage path="/newpage" /> 
    </Router>
)

export default App;

I’m having the same issue but on the index.js page. When running Gatsby Develop I get the navigation.js error. Every other page is fine.

Seems to only happen when I use Gatsby Image/image sharp.

Having the same issue using the same starter template.

For me, removing the line <MDXRenderer>{post.body}</MDXRenderer> in src/templates/blog-post.js made all the pages under /blog load instantly. I’d not made any changes to the starter project up to this point (other than fixing all the errors OOTB). The content on each blog post page still loads, and there’s no console errors. Yet.

– EDIT – It appears just using the tags <MDXRenderer></MDXRenderer> also breaks the page display