Skip to content

Conversation

@mansaj
Copy link
Collaborator

@mansaj mansaj commented Oct 15, 2025

References:

Jira: MNTOR-5071
Figma:

Description

We are getting this error when running a cronjob:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/node_modules/next/headers' imported from /app/dist/scripts/cronjobs/emailBreachAlerts.js"

The issue seems to be introduced recently via an import:

emailBreachAlerts.tsx calls getExperiments()
getExperiments() calls getEnabledFeatureFlags()
getEnabledFeatureFlags() has an unprotected import("next/headers") (line 96)

getEnabledFeatureFlags() had await import("next/headers") with NO error handling. Here we wrap it so that it's "protected"

Screenshot (if applicable)

Not applicable.

How to test

Checklist (Definition of Done)

  • Localization strings (if needed) have been added.
  • Commits in this PR are minimal and have descriptive commit messages.
  • I've added or updated the relevant sections in readme and/or code comments
  • I've added a unit test to test for potential regressions of this bug.
  • If this PR implements a feature flag or experimentation, I've checked that it still works with the flag both on, and with the flag off.
  • If this PR implements a feature flag or experimentation, the Ship Behind Feature Flag status in Jira has been set
  • Product Owner accepted the User Story (demo of functionality completed) or waived the privilege.
  • All acceptance criteria are met.
  • Jira ticket has been updated (if needed) to match changes made during the development process.
  • Jira ticket has been updated (if needed) with suggestions for QA when this PR is deployed to stage.

@mansaj mansaj marked this pull request as ready for review October 15, 2025 21:19
Copy link
Collaborator

@Vinnl Vinnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Florian added the loadNextHeaders function for exactly this purpose. See e.g. here:

const nextHeaders = await loadNextHeaders();

We don't need to log an error - it is expected that we can't read request headers in cronjobs, so that would add noise to every log.

That said, it's also not clear to me that this would cause the error - as far as I can see, the import is only called if $E2E_TEST_ENV === "local", which I assume is not the case when the cron job is running? I also can't reproduce it when running the cronjob locally.

Edit: actually, it looks like that var is set - that seems problematic.

As an aside, while I can't reproduce the exact error, I get this:

Failed to add email notification to table:  Error: `headers` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context

Which is how I'd expect it to go wrong. The error we're seeing in the actual logs seems to imply that next isn't even installed, even though it's one of the dependencies? Or perhaps we're running an old version of Node there that can't do subpath imports?

Edit: here's what I think should fix this: #6190

The functional test is still failing. It appears that for some reason, the test user is logged out after the account is created. I don't know why yet.

@mansaj mansaj closed this Oct 16, 2025
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.

4 participants