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

TypeError when building project, after upgrading to v2.0.0-beta.19 #7398

Closed
5 of 7 tasks
becca-tiessen opened this issue May 11, 2022 · 56 comments
Closed
5 of 7 tasks
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@becca-tiessen
Copy link

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

While upgrading our project to from Docusaurus v2.0.0-beta.18 to v2.0.0-beta.19 we are now encountering an issue during the build.

Reproducible demo

No response

Steps to reproduce

  1. Upgrade docusaurus using the command npm i @docusaurus/[email protected] @docusaurus/[email protected] @docusaurus/[email protected] from v2.0.0-beta-18
  2. npm run build

Expected behavior

To have no problems building. The chalk_1.default.bold TypeError doesn't seem related to any breaking changes introduced in the beta-19 version and there are no existing related issues either.

Actual behavior

To upgrade, we ran npm i @docusaurus/[email protected] @docusaurus/[email protected] @docusaurus/[email protected].

Then when running npm run build we run into the below output:

TypeError: chalk_1.default.bold is not a function
TypeError: chalk_1.default.bold is not a function
TypeError: chalk_1.default.bold is not a function
TypeError: chalk_1.default.bold is not a function
TypeError: chalk_1.default.bold is not a function
TypeError: chalk_1.default.bold is not a function
TypeError: chalk_1.default.bold is not a function
... (many more times)
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/@babel/core/lib/config/files/configuration.js","moduleName":"./node_modules/@babel/core/lib/config/files/configuration.js","loc":"163:150-157","message":"Critical dependency: require function is used in a way in which dependencies cannot be statically extracted","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/@babel/core/lib/config/files/import.js","moduleName":"./node_modules/@babel/core/lib/config/files/import.js","loc":"9:9-25","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/@babel/core/lib/config/files/module-types.js","moduleName":"./node_modules/@babel/core/lib/config/files/module-types.js","loc":"89:17-34","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/@babel/core/lib/config/files/plugins.js","moduleName":"./node_modules/@babel/core/lib/config/files/plugins.js","loc":"148:144-151","message":"Critical dependency: require function is used in a way in which dependencies cannot be statically extracted","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/@babel/helper-define-polyfill-provider/lib/node/dependencies.js","moduleName":"./node_modules/@babel/helper-define-polyfill-provider/lib/node/dependencies.js","loc":"32:13-20","message":"Critical dependency: require function is used in a way in which dependencies cannot be statically extracted","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/@babel/helper-define-polyfill-provider/lib/node/dependencies.js","moduleName":"./node_modules/@babel/helper-define-polyfill-provider/lib/node/dependencies.js","loc":"54:6-13","message":"Critical dependency: require function is used in a way in which dependencies cannot be statically extracted","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/@svgr/core/dist/index.js","moduleName":"./node_modules/@svgr/core/dist/index.js","loc":"159:33-52","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/browserslist/node.js","moduleName":"./node_modules/browserslist/node.js","loc":"171:18-76","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/browserslist/node.js","moduleName":"./node_modules/browserslist/node.js","loc":"171:26-33","message":"Critical dependency: require function is used in a way in which dependencies cannot be statically extracted","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/browserslist/node.js","moduleName":"./node_modules/browserslist/node.js","loc":"192:16-195:6","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/browserslist/node.js","moduleName":"./node_modules/browserslist/node.js","loc":"192:24-31","message":"Critical dependency: require function is used in a way in which dependencies cannot be statically extracted","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/import-fresh/index.js","moduleName":"./node_modules/import-fresh/index.js","loc":"32:31-48","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/svgo/lib/svgo-node.js","moduleName":"./node_modules/svgo/lib/svgo-node.js","loc":"22:13-32","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/svgo/lib/svgo-node.js","moduleName":"./node_modules/svgo/lib/svgo-node.js","loc":"27:42-75","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/svgo/lib/svgo-node.js","moduleName":"./node_modules/svgo/lib/svgo-node.js","loc":"32:17-36","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[WARNING] {"moduleIdentifier":"/Users/rebecca.tiessen/workspace/developer-docs/node_modules/url-loader/dist/index.js","moduleName":"./node_modules/url-loader/dist/index.js","loc":"120:19-42","message":"Critical dependency: the request of a dependency is an expression","compilerPath":"server"}
[ERROR] Unable to build website for locale en.
[ERROR] Error: Failed to compile with errors.
    at /Users/rebecca.tiessen/workspace/developer-docs/node_modules/@docusaurus/core/lib/webpack/utils.js:182:24
    at /Users/rebecca.tiessen/workspace/developer-docs/node_modules/webpack/lib/MultiCompiler.js:554:14
    at processQueueWorker (/Users/rebecca.tiessen/workspace/developer-docs/node_modules/webpack/lib/MultiCompiler.js:491:6)
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

Screen Shot 2022-05-10 at 4 21 06 PM

Apologies for not creating a reproducible demo, if that's necessary to get this looked at then we can potentially schedule it into our work flow but we've spent a good amount of work time trying to debug this already. Thanks in advance if you're able to provide any insights!

Your environment

  • Public source code: n/a (not public)
  • Public site URL: https://developer.boldcommerce.com/default/
  • Docusaurus version used: 2.0.0-beta-18
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Node 16.3
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): macOS Monterey 12.3.1

Self-service

  • I'd be willing to fix this bug myself.
@becca-tiessen becca-tiessen 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 May 11, 2022
@Josh-Cena
Copy link
Collaborator

Josh-Cena commented May 11, 2022

  1. Please upgrade to beta.20, which fixed the "moduleIdentifier" warnings you mentioned.
  2. Please clear your node_modules entirely, and delete your lockfile, and re-install. Every time someone reports this chalk_1.default error, re-installing seems to fix it.

@Josh-Cena Josh-Cena added status: needs more information There is not enough information to take action on the issue. and removed status: needs triage This issue has not been triaged by maintainers labels May 11, 2022
@becca-tiessen
Copy link
Author

beta.20 did remove the warnings, thanks!

As for the second suggestion, it got rid of the chalk_1 problem, but seems to have made a new/different issue visible, has this been reported before?

...
[ERROR] Docusaurus server-side rendering could not render static page with path "/guides/subscriptions-v2/subscription-builder".
[ERROR] Docusaurus server-side rendering could not render static page with path "/guides/subscriptions-v2/headless/storefront-setup".
[ERROR] Docusaurus server-side rendering could not render static page with path "/guides/subscriptions-v2".
[ERROR] Docusaurus server-side rendering could not render static page with path "/guides/subscriptions-v2/subscription-builder/checkout-flow".
[ERROR] Docusaurus server-side rendering could not render static page with path "/guides/subscriptions-v2/subscription-builder/customer-selections-flow".
[ERROR] Docusaurus server-side rendering could not render static page with path "/guides/subscriptions-v2/update-subscription".
[ERROR] Docusaurus server-side rendering could not render static page with path "/guides/subscriptions-v2/webhooks".
[ERROR] Docusaurus server-side rendering could not render static page with path "/guides/subscriptions-v2/widgets".
[ERROR] Docusaurus server-side rendering could not render static page with path "/guides/subscriptions-v2/subscription-builder/entities".
[ERROR] Docusaurus server-side rendering could not render static page with path "/".


TypeError [ERR_INVALID_URL]: Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
TypeError: content.replace is not a function
TypeError: content.replace is not a function
TypeError: content.replace is not a function
TypeError: content.replace is not a function
TypeError: content.replace is not a function
TypeError: content.replace is not a function
TypeError: content.replace is not a function
TypeError: content.replace is not a function
TypeError: content.replace is not a function
TypeError: content.replace is not a function
TypeError: content.replace is not a function
... (more)
[ERROR] Unable to build website for locale en.
[ERROR] Error: Failed to compile with errors.
    at /Users/rebecca.tiessen/workspace/developer-docs/node_modules/@docusaurus/core/lib/webpack/utils.js:182:24
    at /Users/rebecca.tiessen/workspace/developer-docs/node_modules/webpack/lib/MultiCompiler.js:554:14
    at processQueueWorker (/Users/rebecca.tiessen/workspace/developer-docs/node_modules/webpack/lib/MultiCompiler.js:491:6)
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

@Josh-Cena
Copy link
Collaborator

No, I've not seen this before. Would be great if you can provide an isolated repro, thanks!

@sserrata
Copy link
Contributor

For what it's worth, we encountered a similar issue when attempting to upgrade our plugin from beta.18 to beta.19 and then beta.20. Seeing same exact errors. Can reproduce it and link to a PR if it could be helpful?

@becca-tiessen
Copy link
Author

becca-tiessen commented May 11, 2022

@sserrata That would definitely be helpful, our repo is private so to create a demo with the issue reproduced will likely take some time. Thanks!

@sserrata
Copy link
Contributor

sserrata commented May 11, 2022

Reproduces Type Errors Observed in 2.0.0-beta.20

Variant 1

PR: PaloAltoNetworks/docusaurus-openapi-docs#81
Build output: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/runs/6396242136?check_suite_focus=true
Description: Reproduces the TypeError: chalk_1.default.bold is not a function error.

Variant 2

PR: PaloAltoNetworks/docusaurus-openapi-docs#82
Build output: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/runs/6396568165?check_suite_focus=true
Description: Reproduces the TypeError: content.replace is not a function error.

Variant 3

Description: Reproduces the TypeError: content.replace is not a function error on a standalone site.
Repo: https://github.com/sserrata/docusaurus-type-error
Note: Repo intentionally contains entire build directory and node_modules to aid in troubleshooting.

@aerovulpe
Copy link
Contributor

I believe this issue is affecting the redocusaurus plugin too.

rohit-gohri/redocusaurus#175

@Josh-Cena
Copy link
Collaborator

Thanks @sserrata I will start with your isolated repro with the content.replace issue. The chalk_1.default one is very unstable and re-installing almost always fixes, so it's relatively low-priority.

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented May 13, 2022

Can I get a confirmation that everyone running into this issue is using some kind of redoc/open API plugin? I did some preliminary hacks and found that the content.replace problem is coming from a stripBom function, which does not sound familiar to me.

@sproot
Copy link

sproot commented May 13, 2022

We have the same issue with redocusaurus but at 2.0.0-beta.18. There is a single error:

TypeError [ERR_INVALID_URL]: Invalid URL

The error appeared since May 11th. On May 10th, the exactly same build process passed without any issues.

@sserrata
Copy link
Contributor

sserrata commented May 13, 2022

Can I get a confirmation that everyone running into this issue is using some kind of redoc/open API plugin? I did some preliminary hacks and found that the content.replace problem is coming from a stripBom function, which does not sound familiar to me.

We are indeed running an OpenAPI plugin although the error occurs only when we include the accompanying theme (since the plugin only extends the docusaurus CLI).

I ran yarn why strip-bom-string and it seems to be introduced by @docusaurus/utils via the gray-matter package.

yarn why v1.22.18
[1/4] 🤔  Why do we have the module "strip-bom-string"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "[email protected]"
info Reasons this module exists
   - "_project_#docusaurus-plugin-openapi-docs#@docusaurus#utils#gray-matter" depends on it
   - Hoisted from "_project_#docusaurus-plugin-openapi-docs#@docusaurus#utils#gray-matter#strip-bom-string"
info Disk size without dependencies: "16KB"
info Disk size with unique dependencies: "16KB"
info Disk size with transitive dependencies: "16KB"
info Number of shared dependencies: 0

yarn why strip-bom:

yarn why v1.22.18
[1/4] 🤔  Why do we have the module "strip-bom"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "[email protected]"
info Has been hoisted to "strip-bom"
info Reasons this module exists
   - "workspace-aggregator-c9e524fe-827a-4418-9f65-04fba450e1b0" depends on it
   - Hoisted from "_project_#read-pkg#load-json-file#strip-bom"
   - Hoisted from "_project_#eslint-plugin-import#tsconfig-paths#strip-bom"
info Disk size without dependencies: "16KB"
info Disk size with unique dependencies: "16KB"
info Disk size with transitive dependencies: "16KB"
info Number of shared dependencies: 0
=> Found "load-json-file#[email protected]"
info This module exists because "_project_#load-json-file" depends on it.
info Disk size without dependencies: "20KB"
info Disk size with unique dependencies: "20KB"
info Disk size with transitive dependencies: "20KB"
info Number of shared dependencies: 0
=> Found "jest-runtime#[email protected]"
info This module exists because "_project_#jest#@jest#core#jest-runtime" depends on it.
info Disk size without dependencies: "20KB"
info Disk size with unique dependencies: "20KB"
info Disk size with transitive dependencies: "20KB"
info Number of shared dependencies: 0
✨  Done in 0.70s.

@Josh-Cena
Copy link
Collaborator

Thanks. I'm a bit busy these days with other business, while @slorber is on holiday. I'll try to spare some time in the next few days to debug this. Thanks again to everyone for staying around and helping out!

@becca-tiessen
Copy link
Author

Can I get a confirmation that everyone running into this issue is using some kind of redoc/open API plugin? I did some preliminary hacks and found that the content.replace problem is coming from a stripBom function, which does not sound familiar to me.

Can confirm, we're also using redocusaurus!

@rohit-gohri
Copy link
Contributor

rohit-gohri commented May 14, 2022

The chalk_1.default one is very unstable and re-installing almost always fixes, so it's relatively low-priority.

@Josh-Cena I've been trying to fix this on the redocusaurus side today. And for me this is the error troubling me, even on a fresh install. Build Logs: https://github.com/rohit-gohri/redocusaurus/runs/6432967265?check_suite_focus=true

PR open here: rohit-gohri/redocusaurus#176

It seems every time there is a new beta it breaks my plugin. Is there anyway we can declare compatibility with docusaurus versions in the plugin's package.json?

So that users are warned on upgrading past supported versions or something like that? It takes quite some time and effort to support the latest beta and fix the builds.

@Josh-Cena
Copy link
Collaborator

Is there anyway we can declare compatibility with docusaurus versions in the plugin's package.json?

There isn't an official way to do this, but you can import @docusaurus/core/package.json to read its version.

It takes quite some time and effort to support the latest beta and fix the builds.

I'm still not sure if it's a Docusaurus bug or a bug in redocusaurus yet...

@rohit-gohri
Copy link
Contributor

rohit-gohri commented May 14, 2022

I'm still not sure if it's a Docusaurus bug or a bug in redocusaurus yet...

It was an issue in redocusaurus, I've released a new version with the fix: https://github.com/rohit-gohri/redocusaurus/releases/tag/v1.0.4

But there is some issue in Docusaurus too because the error was due to [ERR_INVALID_URL]: Invalid URL, but this was not showing up due to chalk errors.

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented May 14, 2022

but this was not showing up due to chalk errors.

Yeah, the chalk error only shows up when SSR throws because of some other error. It doesn't reproduce consistently, so I can't say what's wrong (I haven't seen it myself in SSR failures in a while). Hopefully, when we emit ESM code during SSR (which will not be very distant), this will be gone since we won't worry about all the interop mess :)

If it's fixed, can I close this now? I'd like the folks who joined this thread to give a confirmation that the latest patch fixes everything.

@Josh-Cena Josh-Cena added the external This issue is caused by an external dependency and not Docusaurus. label May 14, 2022
@mmartev
Copy link

mmartev commented May 14, 2022

Seems to be ok with 1.0.4 of redocusaurus, my project now builds ok.

@markkane
Copy link

We are having the same problem when moving our code to a version of docusaurus > than beta.18. SSR builds to 92%, then:

[the next line x30]
[ERROR] Docusaurus server-side rendering could not render static page with path "/docs/roadmap".

TypeError: content.replace is not a function
[the previous line x30]

We do not use redocusaurus, but we do use another OpenAPI Module called RapiDoc (wrapped in BrowserOnly).

@Josh-Cena
Copy link
Collaborator

From rohit-gohri/redocusaurus#178, it looks like @rohit-gohri fixed it by adding the tty polyfill? I'm not sure what we need to do on our side, since the bug with redocusaurus is indeed fixed without us doing anything.

@markkane
Copy link

I wish I could give more useful information. We have docusaurus-node-polyfills in our project, which includes tty, so I don't think that is causing our problems. I even tried reproducing the tty fix in the PR you linked, but it doesn't change anything for us.

All I can say for sure is our build breaks when upgrading from beta.18 -> beta.19 or beta.20. No other changes on our side. Maybe another plugin or customization is involved or even the cause, but upgrading docusaurus triggers the problem and apparently it doesn't only happen for projects using redocusaurus.

@sserrata
Copy link
Contributor

If you don't mind the bother, you can also help us track down the actual issue by bisecting the canary releases. beta.18 corresponds to 0.0.0-4778, while beta.20 is 0.0.0-4982. If something broke your plugin, it must occur in one of the 126 versions in between. 7 install/builds would be enough to narrow it down to one version.

@Josh-Cena, after some testing, I believe that our builds start failing at 0.0.0-4875 with the TypeError: chalk_1.default.bold is not a function error. The last canary release with a successful build is (the one right before) 0.0.0-4873.

@Josh-Cena
Copy link
Collaborator

@sserrata Thanks a lot for that information! 0.0.0-4875 is #7186, which does look like there's a chance of breaking the build.

I would look into this. Thanks again! Much appreciated.

@Josh-Cena
Copy link
Collaborator

@sserrata If you are interested in investigating further, you can try replacing await fs.readJSON(manifestPath) in node_modules/@docusaurus/core/lib/client/serverEntry.js with JSON.parse(await fs.readFile(manifestPath, 'utf8')) and see if it fixes your error.

@sserrata
Copy link
Contributor

If you are interested in investigating further, you can try replacing await fs.readJSON(manifestPath) in node_modules/@docusaurus/core/lib/client/serverEntry.js with JSON.parse(await fs.readFile(manifestPath, 'utf8')) and see if it fixes your error.

@Josh-Cena Yes, that appears to have fixed the error. With that fix I was able to work my way up to 0.0.0-4893 before encountering a new error in 0.0.0-4894:

Attempted import error: 'decodedMap' is not exported from '@jridgewell/gen-mapping' (imported as 'decodedMap').
Attempted import error: 'encodedMap' is not exported from '@jridgewell/gen-mapping' (imported as 'encodedMap').
TypeError: Cannot read properties of undefined (reading 'split')

@sserrata
Copy link
Contributor

@Josh-Cena, taking a stab in the dark but any chance the source of the error could be the markdownUtils.ts module included in @docusaurus/utils? It seems to have a plethora of content.replace occurrences and was last updated about 2 months ago. However, the timing may not line up with 2.0.0-beta.19 release.

@markkane
Copy link

@sserrata If you are interested in investigating further, you can try replacing await fs.readJSON(manifestPath) in node_modules/@docusaurus/core/lib/client/serverEntry.js with JSON.parse(await fs.readFile(manifestPath, 'utf8')) and see if it fixes your error.

Thanks @Josh-Cena: changing this line fixes the build errors for me. Site builds normal in beta.20 now locally, doesn't fix the pipeline of course.

@ckailash
Copy link

I just wanted to chime in and say that I'm using https://github.com/stoplightio/elements/, and I'm running into the same issue discussed here!

@snikch
Copy link

snikch commented May 20, 2022

I'm another user of Stoplight Elements with this issue.

@Josh-Cena
Copy link
Collaborator

I think the culprit here is indeed about the Buffer polyfill. The error is thrown from here: https://github.com/jprichardson/node-jsonfile/blob/a5414d716dd5ea21aa9327bdebaefa75f0bcf5d1/utils.js#L8-L12 (which is called by fs.readJSON, which I recommended to replace above). The reason is because during SSR, Buffer is already available in the global scope and doesn't need to be polyfilled. I don't know how these polyfills are applied and whether they check existing globals first, but indeed Buffer.isBuffer(content) returned false even when the file is actually still a buffer.

I'm going to avoid using logger and readJSON in server entry, but ideally we should figure out a better way to do this.

@rohit-gohri
Copy link
Contributor

I think the polyfill is only replacing the require('buffer') calls and not the global Buffer. If we add polyfill for both (module and global) then it might be fixed?

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented May 20, 2022

In any case, I've merged #7453 which avoids using some "risky" globals in SSR. I'm hoping 0.0.0-5034 would fix everyone's errors; I don't really want to think too deeply about this😄

@snikch
Copy link

snikch commented May 20, 2022

Works for me ❤️

@Josh-Cena
Copy link
Collaborator

Great! Seems we've already have success stories from the majority, either because of @rohit-gohri's fix or from #7453. Specifically, I hope that the following errors no longer appear after using Canary:

  • TypeError: chalk_1.default.bold is not a function
  • TypeError: content.replace is not a function
  • TypeError [ERR_INVALID_URL]: Invalid URL

I'm going to close this as resolved then. If there are any lingering errors just let me know below, and we can take another look.

@Josh-Cena Josh-Cena removed status: needs more information There is not enough information to take action on the issue. external This issue is caused by an external dependency and not Docusaurus. labels May 20, 2022
@sibelius
Copy link

do we need to wait a new release to get the fix?

is there a patch package for this?

@Josh-Cena
Copy link
Collaborator

Please use the canary release. (We have been talking about canary a lot above)

@sserrata
Copy link
Contributor

Works for our plugin as well! Thanks again for everyone's help! 🥳

@sgrund14
Copy link

sgrund14 commented May 20, 2022

I was getting the chalk_1.default.bold is not a function error but I just fixed it thanks to this thread 😄

the problem was this polyfill code which I had in a component definition file after the initial imports (so run on the server)

if (!window.Buffer) {
  window.Buffer = Buffer;
}

I fixed it by updating it to

if (typeof window !== "undefined" && !window.Buffer) {
  window.Buffer = Buffer;
}

guess it makes sense that window would be undefined on the server but yes the error message was a bit confusing 😅

tried updating the canary version too, but that didn't work as the error was in my own code. #7456 covers the issue, I think

@alirezamirian
Copy link

alirezamirian commented Jun 17, 2022

I'm still experiencing this issue. Tried beta.20 and beta.21 as well. Tried yarn clear and removing yarn.lock file too.

UPDATE: In my case, only one version of both chalk and tslib was installed, and exactly the versions @docusaurus/logger requested for. So I doubt if it was a dependency graph issue.
In case it helps others with the same issue: I edited node_modules/@docusaurus/logger/lib/index.js manually and removed the use of chalk_1.default.bold in error function:

function error(msg, ...values) {
    console.error(stringify(msg));
}

That helped in getting the actual SSR error, at least.

@markerikson
Copy link

markerikson commented Jun 26, 2022

I just tried upgrading Redux Toolkit's website from beta.7 to beta.21, and I'm seeing a variation on this error as well:

TypeError: source_default(...).bold is not a function
TypeError: source_default(...).bold is not a function
TypeError: source_default(...).bold is not a function
[ERROR] Unable to build website for locale en.
[ERROR] Error: Failed to compile with errors.
    at D:\Projects\redux\redux-toolkit\node_modules\@docusaurus\core\lib\webpack\utils.js:180:24

edit

Hmm. After going into serverEntry.js inside of node_modules, and commenting out every use of chalk in the error handling, and adding an additional console.error('Actual error: ', err) statement, I'm finally getting something meaningful:

[ERROR] Docusaurus server-side rendering could not render static page with path /rtk-query/usage/error-handling.
Actual error:  ReactContextError
    at useDocsVersion (main:9127:99)
    at DocVersionBanner (main:9136:814)
    at zb (main:81525:195)
    at Cb (main:81528:254)
    at W (main:81534:89)
    at Db (main:81537:98)
    at Eb (main:81536:122)
    at W (main:81534:345)
    at Db (main:81537:98)
    at Cb (main:81529:131) {
  message: 'Hook useDocsVersion is called outside the <DocsVersionProvider>. '
}

except that seems to be internal to Docusaurus and I have no idea why that provider doesn't exist.

so, three problems here:

  • The actual error isn't being printed at all
  • The chalk usages appear to be broken
  • I'm getting this useDocsVersion error just from upgrading DS

*edit 2

And confirmed that I'm seeing the same build failures in CI:

reduxjs/redux-toolkit#2458

@Josh-Cena
Copy link
Collaborator

@markerikson Could you open a new issue or ask in discussions? This issue has been resolved as a plugin polyfilling issue, so yours is probably unrelated. There are many, many things that can cause the chalk usage to be broken (I've hit it quite a few times.) I'm currently on vacation so I probably won't devote a lot of time to debug it until this weekend at least, so it's better if we can track it elsewhere.

@markerikson
Copy link

@Josh-Cena ok, will do!

@tfrijsewijk
Copy link

Leaving it here for fellow Googlers:

I was seeing this error because I had a `style="just-some-string-here" attribute in my .md file:

<p style="background-color: #ebf3e6; width: 100%; height: 150px"></p>

I did the same that @markerikson did here which resulted in the following build error:

Error: The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.

I went on searching for style= when I noticed the markup.

Thanks Mark for the initial hint!

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