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

[2.0.0-alpha.71] Docusaurus Node/SSR could not render static page with path=[PATH] because of error: Cannot read property 'replace' of undefined #4421

Closed
johnnyreilly opened this issue Mar 13, 2021 · 5 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@johnnyreilly
Copy link
Contributor

johnnyreilly commented Mar 13, 2021

Heya!

I've a fairly vanilla Docusaurus site that I'm using for blogging alone. I think (I'm not sure) that the problem may lie with the @docusaurus/plugin-client-redirects. Actually I think not; I tried excluding that plugin and the issue still presented.

🐛 Bug Report

I think I've just encountered a bug with Docusaurus 2.0.0-alpha.71. I upgraded from 70 and started to encounter error messages in the build of the nature of:

Docusaurus Node/SSR could not render static page with path=/tags/fork-ts-checker-webpack-plugin because of error: Cannot read property 'replace' of undefined

and stack traces like

(undefined) TypeError: Cannot read property 'replace' of undefined
    at CodeBlock (main:8985:18)
    at d (main:72375:498)
    at $a (main:72378:16)
    at a.b.render (main:72383:476)
    at a.b.read (main:72383:18)
    at Object.renderToString (main:72393:364)
    at doRender (main:90314:385)
    at async serverEntry_render (main:90313:301)

You can see a PR here which solely upgrades from 70 to 71 which leads to the issue: johnnyreilly/blog.johnnyreilly.com#15

See the failing build which happens as a consequence of the upgrade here: https://github.com/johnnyreilly/blog.johnnyreilly.com/pull/15/checks?check_run_id=2101336052

Have you read the Contributing Guidelines on issues?

Yes!

To Reproduce

git clone https://github.com/johnnyreilly/blog.johnnyreilly.com.git
cd blog.johnnyreilly.com
git checkout feat/upgrade-deps
cd blog-website
yarn
yarn build

Expected behavior

Compilation with warnings but no errors.

Actual Behavior

Many errors of the nature:

Docusaurus Node/SSR could not render static page with path=/tags/windows-defender because of error: Cannot read property 'replace' of undefined
Docusaurus Node/SSR could not render static page with path=/tags/wkhtmltopdf because of error: Cannot read property 'replace' of undefined

Your Environment

Reproducible Demo

See To Reproduce.

@johnnyreilly johnnyreilly added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Mar 13, 2021
@johnnyreilly johnnyreilly changed the title v71 Docusaurus Node/SSR could not render static page with path=[PATH] because of error: Cannot read property 'replace' of undefined [2.0.0-alpha.71] Docusaurus Node/SSR could not render static page with path=[PATH] because of error: Cannot read property 'replace' of undefined Mar 13, 2021
@lex111
Copy link
Contributor

lex111 commented Mar 13, 2021

Thanks for the report, it will be fixed in #4428.

However, I should inform you that due to the specificities of JSX, the contents of pre will be rendered in one line (i.e. without expected line breaks). To avoid this, you will either need to use a triple backtick or the CodeBlock component. I don't know how to automate this for you, but to get the correct code blocks formatting you need to use one of these methods.

@johnnyreilly
Copy link
Contributor Author

Ah fascinating - yeah it turns out there's some <pres tucked away in some historic blogs. I'll have to fix these up

https://github.com/johnnyreilly/blog.johnnyreilly.com/search?q=pre&type=

@johnnyreilly
Copy link
Contributor Author

Cleaned my <pres - this turns out to have been a helpful bug to me 😄

@sriramgroot
Copy link

While i run npm run build, now iam getting the below mentioned error in terminal

Docusaurus Node/SSR could not render static page with path=/ because of error: window is not defined

Could you please help me in this issue to solve.

@slorber
Copy link
Collaborator

slorber commented Oct 19, 2021

@sriramgroot this question has been asked a lot and you'll find refs in many other issues. It's not directly related to Docusaurus: this error can happen in any React+SSR framework (Next, Gatsby, Docusaurus...).

You are either using window, or importing a lib that uses window during SSR/Node.js build, where this variable is not available.

@Josh-Cena Josh-Cena removed the status: needs triage This issue has not been triaged by maintainers label Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution
Projects
None yet
Development

No branches or pull requests

5 participants