Build fails when config includes redocusaurus and docusaurus-theme-search-typesense
Description
Hi
I'm getting a build error when I compile with 2 plugins in the same config
- redocusaurus 1.3.0
- docusaurus-theme-search-typesense 0.7.0-0
I also wanted to note that I only run into this error when running npm run build if i do npm start everything works fine with both plugins available in the docusaurus config.
I've tried a mix of the following
- rm -rf node_modules package-lock.json and reinstall
- downgrading docusaurus to v2.0.1
- upgrading to docusaurus v2.1.0
I've noticed that if I were to comment out the redocusaurus config in presets of docusaurus.config.js OR themes:['docusaurus-theme-search-typesense'] the build happens smoothly
docusaurus.config.js
presets: [
[
'@docusaurus/preset-classic',
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
sidebarPath: require.resolve('./sidebars.js'),
},
blog: false,
theme: {
customCss: require.resolve('./src/css/custom.css'),
},
}),
],
[
'redocusaurus',
{
specs: [
{
spec: require.resolve('./static/api_spec/open-api-spec.yml'),
route: '/api',
},
],
theme: {
primaryColor: '#2e8555',
primaryColorDark: '#25c2a0'
},
},
],
],
themes: ['docusaurus-theme-search-typesense'],
package.json
{
"name": "json-api-docs",
"version": "0.0.0",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc"
},
"dependencies": {
"@docusaurus/core": "^2.1.0",
"@docusaurus/preset-classic": "^2.1.0",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.2.1",
"docusaurus-theme-search-typesense": "^0.7.0-0",
"prism-react-renderer": "^1.3.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"redocusaurus": "^1.3.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^2.1.0",
"@tsconfig/docusaurus": "^1.0.5",
"typescript": "^4.7.4"
},
"browserslist": {
"production": [
">0.5%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"engines": {
"node": ">=16.14"
}
}
error message
[INFO] [en] Creating an optimized production build...
✔ Client
✖ Server
Compiled with some errors in 15.89s
main:55529
{}.DEBUG = namespaces;
^
SyntaxError: Unexpected token '.'
[ERROR] Unable to build website for locale en.
[ERROR] Error: Failed to compile with errors.
at .../json-api-docs/node_modules/@docusaurus/core/lib/webpack/utils.js:180:24
at .../json-api-docs/node_modules/webpack/lib/MultiCompiler.js:554:14
at processQueueWorker (.../json-api-docs/node_modules/webpack/lib/MultiCompiler.js:491:6)
at processTicksAndRejections (node:internal/process/task_queues:78:11)
[INFO] Docusaurus version: 2.1.0
Node version: v16.14.2
Steps to reproduce
- implement redocusaurus
- implement searchbar utilizing typesense
-
npm run buildwith both redocusaurus and docusaurus-theme-search-typesense enabled in the docusaurus config
Expected Behavior
- I would expect the build to be successful / compete
Actual Behavior
- Build fails when compiling the "server"
Metadata
Typsense Version: 0.7.0-0
OS: MacOS Monterey 12.6
I have the exact same issue and to be honest I have no idea where to even start debugging it.
I made a minimal example to reproduce the build error, I hope it will help whoever can debug this:
https://github.com/balazsbotond/redocusaurus-typesense-bug-repro
Please note that @GalexyN also reported the same issue here: https://github.com/rohit-gohri/redocusaurus/issues/236
I've found a closed issue about the same problem in the debug.js project.
A PR which fixed this issue with minimal changes was rejected with the justification that "it wasn't the maintainers' job to fix other people's messes". Another PR which may fix this issue has been open for more than four years.
The original issue offers several possible workarounds by defining webpack plugins but I'm not sure these can be added to a Docusaurus project.
One of my coworkers suggested simply commenting out the offending line in the node_modules folder (node_modules/debug/src/node.js):
function save(namespaces) {
if (namespaces) {
// process.env.DEBUG = namespaces;
} else {
// If you set a process.env field to null or undefined, it gets cast to the
// string 'null' or 'undefined'. Just delete instead.
delete process.env.DEBUG;
}
}
Which, while being an incredibly hacky solution, is the one we currently use as part of our CI pipeline by running the following sed command after installing npm packages:
sed -i '/process.env.DEBUG = namespaces;/c\// process.env.DEBUG = namespaces;' ./node_modules/debug/src/node.js
Far from ideal, I know, but I hope it helps someone until the root cause is fixed.