fix(table-core): guard process.env checks for non-bundled environments by isaackaara · Pull Request #6185 · TanStack/table · GitHub
Skip to content

fix(table-core): guard process.env checks for non-bundled environments#6185

Open
isaackaara wants to merge 2 commits intoTanStack:mainfrom
isaackaara:fix/process-not-defined-vanilla-js
Open

fix(table-core): guard process.env checks for non-bundled environments#6185
isaackaara wants to merge 2 commits intoTanStack:mainfrom
isaackaara:fix/process-not-defined-vanilla-js

Conversation

@isaackaara
Copy link
Copy Markdown

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 — Added isDev() utility
  • packages/table-core/src/core/column.ts — 2 occurrences
  • packages/table-core/src/core/table.ts — 3 occurrences
  • packages/table-core/src/utils/getFilteredRowModel.ts — 1 occurrence

Closes #6078

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-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 4, 2026

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 4, 2026

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.

1 participant