website: fix build failure when popular issues data is absent
Problem
On a fresh checkout, npm run build (and npm start) fail to compile:
× Cannot find module '@site/static/data/popular-issues.json' for matched aliased key '@site'
[ERROR] Client bundle compiled with errors therefore further build is impossible.
src/components/GitHubIssues.tsx loads @site/static/data/popular-issues.json via require(). The webpack bundle resolves that import at build time, so the try/catch around it cannot prevent the failure. The file is produced by npm run fetch-popular-issues (which needs a GitHub token) and is gitignored (static/data/*), so it does not exist after a clean clone.
CI builds succeed only because the workflow runs fetch-popular-issues before build. The local workflow documented in website/README.md (npm start / npm run build) does not mention that step, so a new contributor following the docs hits the error — on the page that renders the Contribute doc, no less.
Fix
Add scripts/ensure-popular-issues.mjs, wired as prestart/prebuild, that writes an empty [] fallback when the file is missing. When the file already exists (CI, or after a manual fetch) it is left untouched, so real data and CI behavior are unchanged. GitHubIssues already renders an empty state when there are no issues.
Verification
- Fresh state (no
static/data/):npm run buildfailed before, succeeds after. - With existing data present: the file is not overwritten.
npm run typecheckandnpm run lintpass.
Reproduce
cd website
npm install
npm run build # fails on main, succeeds with this change
Preview: https://devin-lai.github.io/openarm
See https://github.com/enactic/openarm/blob/main/website/README.md#pull-request-and-preview how to configure preview on fork.
Does this really happen?
We ignore @site/static/data/popular-issues.json not found error:
https://github.com/enactic/openarm/blob/5d878b697c24e944f6c6b89d67050c7d07d00602/website/src/components/GitHubIssues.tsx#L108-L113
Does this really happen?
We ignore
@site/static/data/popular-issues.jsonnot found error:https://github.com/enactic/openarm/blob/5d878b697c24e944f6c6b89d67050c7d07d00602/website/src/components/GitHubIssues.tsx#L108-L113
Yeah, I hit it on a fresh checkout. The require('@site/static/data/popular-issues.json') is resolved at build time, so the missing file becomes a bundler error before the try/catch can return [].
Repro: cd website mv static/data/popular-issues.json /tmp/ npx docusaurus build
It exits with Cannot find module '@site/static/data/popular-issues.json' Since static/data/* is gitignored and the file only exists after fetch-popular-issues, an empty [] is enough to unblock the build. No worries if you still can’t repro — feel free to ignore this if it’s too minor
@otegami Could you check this case?
@devin-lai How about #533?
@devin-lai How about #533? #533 looks great to me, thanks
I closed this in favor of #533.