Skip to content

fix: export NR_SITES from constants so it is no longer undefined - #1185

Open
akashreddy-nr wants to merge 1 commit into
developfrom
akash/fix-nr-sites-export
Open

akashreddy-nr wants to merge 1 commit into
developfrom
akash/fix-nr-sites-export

Conversation

@akashreddy-nr

@akashreddy-nr akashreddy-nr commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

NR_SITES has been exported as undefined from the package root since 9.9.0. Any consumer that reads a property off it crashes at build time.

Cause: the search redesign (#1097, commit 083cd831) moved NR_SITES from GlobalHeader.js into src/utils/constants.js, but index.js kept re-exporting it from ./src/components/GlobalHeader. That module only has a default export now, so webpack resolves the named re-export to undefined and only logs a warning:

export 'NR_SITES' (reexported as 'NR_SITES') was not found in './src/components/GlobalHeader' (possible exports: default)

yarn lint doesn't cover index.js, so it wasn't caught.

Changes

  • index.js: re-export NR_SITES from ./src/utils/constants.
  • index.js: drop the SWIFTYPE_ENGINE_KEY re-export. It was removed from constants.js in the SearchGPT migration (c90a553d) and has also been undefined since. No repo in the newrelic org imports it.
  • New src/__tests__/exports.test.js: fails if any named export from the package root is undefined, so this class of bug fails CI next time. Without the fix it fails on NR_SITES and SWIFTYPE_ENGINE_KEY; with the fix it passes.
  • README: the GlobalHeader example used GlobalHeader.NR_SITES.IO, which never existed. It now shows import { GlobalHeader, NR_SITES } and NR_SITES.DOCS.

Impact on consumers

  • developer-website (src/layouts/MainLayout.js uses NR_SITES.DEVELOPER): broken on every theme version from 9.9.0. With this fix, NR_SITES.DEVELOPER is undefined (the key was removed in 0e937839), which GlobalHeader accepts, so the build succeeds. Verified with a full gatsby build on theme 9.18.1 plus this patch.
  • docs-website, docs-website-private, beta-docs-site: they don't import NR_SITES or SWIFTYPE_ENGINE_KEY, so there's no behavior change.

Testing

  • npx jest: new export test passes. 90/92 overall; the 2 CodeBlock.test.js failures also fail on a clean develop and are unrelated.
  • developer-website: yarn lint and full yarn build pass against theme 9.18.1 with this index.js.

Related: NR-634009. Found while testing a theme upgrade in developer-website (newrelic/developer-website#2325).

🤖 Generated with Claude Code

The search redesign (#1097, released in 9.9.0) moved NR_SITES from
GlobalHeader.js into utils/constants.js, but index.js kept re-exporting it
from GlobalHeader. Since 9.9.0, `import { NR_SITES } from
'@newrelic/gatsby-theme-newrelic'` has resolved to undefined.

- re-export NR_SITES from utils/constants
- drop the SWIFTYPE_ENGINE_KEY re-export, which was removed from constants
  in the SearchGPT migration and has also been undefined since
- add a test that fails if any named export from the package root is undefined
- fix the GlobalHeader README example (GlobalHeader.NR_SITES.IO never existed)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants