fix: resolve webpack warning for optional date-fns-tz dependency#6182
fix: resolve webpack warning for optional date-fns-tz dependency#6182martijnrusschen wants to merge 3 commits intomainfrom
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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>
535417b to
f492f03
Compare
|
When Here's a relatively recent StackOverflow thread with related example code. It only talks about |
Summary
__non_webpack_require__to load the optionaldate-fns-tzmodulerequireis not availableBackground
When
date-fns-tzis not installed (it's an optional peer dependency), webpack emits a warning because it can't statically analyze the dynamicrequire(variable)pattern. By using webpack's special__non_webpack_require__global, we bypass webpack's bundling analysis while still falling back to regularrequirein non-webpack environments.Vite Support
Vite and other ESM-only bundlers don't provide a
requirefunction. This PR adds a guard to check ifrequireis 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
Fixes #6181
Fixes #6204
🤖 Generated with Claude Code