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.

Cannot read property 'Provider' of undefined. BaseContext from `@reach/router` is undefined.

See original GitHub issue

Description

image

BaseContext is undefined here.

Also, it looks like @reach/router doesn’t export BaseContext 🤔. Ideally gatsby shouldnt’ be relying on this import, if its not actually exported from @reach/router.

NOTE: This issue goes away, if I fix the BaseContext by copying over the snippet to re-create it from here and then patching the production-app.js file inside cache-dir.

  const RouteHandler = props => (
    <BaseContext.Provider
      value={{
        baseuri: `/`,
        basepath: `/`,
      }}
    >
      <PageRenderer {...props} />
    </BaseContext.Provider>
  )

Steps to reproduce

Issue arises especially when I use docker to create a docker image of the source code, and then build the gatsby image, copying the public directory and then use tools like serve to host the static files. This is NOT reproducible on gatsby build or gatsby develop, which makes it even more difficult to debug, on why this issue is happening. I’m unfortunately not able to provide more information due to lack thereof.

Expected Behaviour

Gatsby should handle the BaseContext being undefined error, more gracefully.

Environment

System: OS: macOS 10.15.5 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.18.3 - ~/n/bin/node Yarn: 1.22.4 - ~/.yarn/bin/yarn npm: 6.14.7 - /usr/local/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Edge: 85.0.564.44 Safari: 13.1.1 npmPackages: gatsby: ^2.24.53 => 2.24.54 gatsby-link: ^2.4.13 => 2.4.13 gatsby-plugin-catch-links: ^2.3.5 => 2.3.11 gatsby-plugin-emotion: ^4.3.2 => 4.3.10 gatsby-plugin-gtag: ^1.0.12 => 1.0.13 gatsby-plugin-layout: ^1.3.10 => 1.3.10 gatsby-plugin-manifest: ^2.2.33 => 2.4.28 gatsby-plugin-mdx: ^1.0.61 => 1.2.38 gatsby-plugin-nprogress: ^2.3.2 => 2.3.10 gatsby-plugin-offline: ^3.2.11 => 3.2.27 gatsby-plugin-react-helmet: ^3.1.18 => 3.3.10 gatsby-plugin-remove-serviceworker: ^1.0.0 => 1.0.0 gatsby-plugin-remove-trailing-slashes: ^2.3.5 => 2.3.11 gatsby-plugin-sitemap: ^2.2.24 => 2.4.12 gatsby-remark-autolink-headers: ^2.3.5 => 2.3.12 gatsby-remark-copy-linked-files: ^2.1.33 => 2.3.14 gatsby-source-filesystem: ^2.3.27 => 2.3.28 gatsby-transformer-remark: ^2.8.32 => 2.8.33

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
ZeldOcarinacommented, Oct 14, 2022

Hi! It’s over two years now and I also still have this bug. Is there any way we can help?

1reaction
ahmedragab96commented, Oct 20, 2022

Hello , I am facing same exact issue! any fix or help , please ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

1 Answer - 1 - Stack Overflow
Thanks in advance! Error in function RouteHandler in ./.cache/root.js:21 Cannot read properties of undefined (reading 'Provider') ./.
Read more >
https://preview.lqd.ch/app-40335d38df0f84615d64.js.map
node_modules/core-js/internals/copy-constructor-properties.js","webpack:///. ... __PATH_PREFIX__ : undefined : __PATH_PREFIX__;\n};\n\nvar ...
Read more >
webdoc-labs/www: The source code of the webdoc website! - docs ...
node_modules/@gatsbyjs/reach-router/es/lib/history.js" ... NODE_ENV === \"test\") {\n // getting cannot read property focus of null in the tests\n // and ...
Read more >
router from reach - GithubHelp Home
... TypeError: Cannot read property 'replace' of undefined at segmentize (/Users/ryanflorence/Desktop/test/node_modules/@reach/router/lib/utils.js:243:3) at ...
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