Skip to content

Conversation

@martijnrusschen
Copy link
Member

@martijnrusschen martijnrusschen commented Dec 19, 2025

Summary

  • Uses __non_webpack_require__ to load the optional date-fns-tz module
  • This tells webpack to use the native Node.js require at runtime instead of trying to bundle/analyze the module
  • Eliminates the "Critical dependency: the request of a dependency is an expression" warning
  • Added: Handles ESM-only environments (like Vite) where require is not available

Background

When date-fns-tz is not installed (it's an optional peer dependency), webpack emits a warning because it can't statically analyze the dynamic require(variable) pattern. By using webpack's special __non_webpack_require__ global, we bypass webpack's bundling analysis while still falling back to regular require in non-webpack environments.

Vite Support

Vite and other ESM-only bundlers don't provide a require function. This PR adds a guard to check if require is available before attempting to use it, preventing runtime errors. However, due to the limitations of ESM, Vite users who want timezone support will need to configure their bundler - see #6204 for details.

Test plan

  • TypeScript type checking passes
  • All tests pass
  • Build succeeds and includes the fix in dist output

Fixes #6181
Fixes #6204

🤖 Generated with Claude Code

Use __non_webpack_require__ to load the optional date-fns-tz module.
This tells webpack to use the native Node.js require at runtime instead
of trying to bundle/analyze the module, eliminating the "Critical
dependency: the request of a dependency is an expression" warning.

Fixes #6181

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.29%. Comparing base (644f2f5) to head (f492f03).
⚠️ Report is 31 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6182      +/-   ##
==========================================
- Coverage   99.31%   99.29%   -0.03%     
==========================================
  Files          30       30              
  Lines        3810     3826      +16     
  Branches     1639     1653      +14     
==========================================
+ Hits         3784     3799      +15     
- Misses         25       26       +1     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

martijnrusschen and others added 2 commits December 19, 2025 17:36
Adds a test that simulates a webpack environment by defining
__non_webpack_require__ globally, ensuring the branch that uses
webpack's native require bypass is covered.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added a check for `typeof require !== "undefined"` before attempting to use
require(). This prevents runtime errors in Vite and other ESM-only bundlers
where require is not polyfilled.

Note: Vite users who want timezone support will need to configure their
bundler to pre-bundle date-fns-tz. See issue #6204 for details.

Fixes #6204

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@martijnrusschen martijnrusschen force-pushed the fix/webpack-optional-dep-warning-6181 branch from 535417b to f492f03 Compare January 5, 2026 11:58
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.

Timezone support broken in Vite due to dynamic require of date-fns-tz v.9.1.0 webpack warning (p2)

2 participants