fix(table-core): guard process.env checks for non-bundled environments#6185
fix(table-core): guard process.env checks for non-bundled environments#6185isaackaara wants to merge 2 commits intoTanStack:mainfrom
Conversation
Replaces direct `process.env.NODE_ENV` references with a safe `isDev()` utility that checks for the existence of `process` before accessing it. This prevents `ReferenceError: process is not defined` when using @tanstack/table-core in vanilla JS environments loaded via importmaps (e.g. Rails) without a bundler. The built ESM output preserved raw `process.env.NODE_ENV` references which would throw in environments where `process` is not globally defined. Closes TanStack#6078
🦋 Changeset detectedLatest commit: b170475 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
When using
@tanstack/table-corein vanilla JS without a bundler (e.g., via ES module importmaps in Rails), aReferenceError: process is not definedis thrown because the source code contains rawprocess.env.NODE_ENVreferences.As reported in #6078, the ESM build output preserves these references without any transformation, and environments without Node.js globals (browser ESM via importmaps, Deno, etc.) crash on them.
Root Cause
The source code directly accesses
process.env.NODE_ENVfor development-only warnings and debug logging. While bundlers like Vite/Webpack replace these at build time, the published ESM output retains them as-is, causing errors in unbundled environments.Fix
Introduced a
isDev()utility function that safely checks for the existence ofprocessbefore accessingprocess.env.NODE_ENV:Replaced all direct
process.env.NODE_ENVchecks acrosstable-corewith calls toisDev().Files changed:
packages/table-core/src/utils.ts— AddedisDev()utilitypackages/table-core/src/core/column.ts— 2 occurrencespackages/table-core/src/core/table.ts— 3 occurrencespackages/table-core/src/utils/getFilteredRowModel.ts— 1 occurrenceCloses #6078