fix(table-core): guard process.env checks for non-bundled environments #6185
main fromrefs/pull/6185/head·opened Problem#
When using @tanstack/table-core in vanilla JS without a bundler (e.g., via ES module importmaps in Rails), a ReferenceError: process is not defined is thrown because the source code contains raw process.env.NODE_ENV references.
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_ENV for 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 of process before accessing process.env.NODE_ENV:
export function isDev(): boolean {
return (
typeof process !== 'undefined' &&
process.env?.NODE_ENV !== 'production'
)
}
Replaced all direct process.env.NODE_ENV checks across table-core with calls to isDev().
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 occurrence
Closes #6078
- 1
Important
Review skipped#
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
f0ac146f-7629-4dbe-beeb-2df3c1ff0228You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
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 `@coderabbitai help` to get the list of available commands and usage tips.KevinVandy closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: b170475cdef8189cb52ac741d9de9a5b72c327c5
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