Skip to content

Fix source map generation during when watching files on the CLI#19373

Merged
thecrypticace merged 5 commits intomainfrom
fix/issue-19362
Nov 25, 2025
Merged

Fix source map generation during when watching files on the CLI#19373
thecrypticace merged 5 commits intomainfrom
fix/issue-19362

Conversation

@thecrypticace
Copy link
Contributor

Fixes #19362

We were overwriting the source map with the "decoded" map returned by the compiler but didn't wrap it in the helper intended to help inline vs file maps. This resulted in two issues:

  1. undefined being appended to the CSS file when using --map
  2. undefined being passed to writeFile(…) when using --map <file>

This PR fixes both.

@thecrypticace thecrypticace requested a review from a team as a code owner November 25, 2025 15:02
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 25, 2025

Walkthrough

Replaces direct casting of compiler.buildSourceMap() with toSourceMap(compiler.buildSourceMap()) in the CLI build/rebuild paths to ensure proper SourceMap typing. Adds watch-mode tests covering inline and external source maps, validating initial builds, rebuilds after CSS edits, and parity between CLI and Standalone CLI. Updates CHANGELOG.md with a Fixed entry noting correct source map writing in CLI --watch mode.

Pre-merge checks

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: correcting source map generation during watch mode on the CLI.
Description check ✅ Passed The description clearly explains the root cause and the two issues being fixed, directly relating to the changeset.
Linked Issues check ✅ Passed The PR comprehensively addresses both objectives from issue #19362: fixing 'undefined' appended to CSS with --map and TypeError with --map in watch mode.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing source map generation in watch mode: CHANGELOG entry, tests validating the fix, and the core fix wrapping compiler output with toSourceMap().

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 068a1ec and 12c476d.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • integrations/cli/index.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Linux / postcss
  • GitHub Check: Linux / vite
  • GitHub Check: Linux / cli
  • GitHub Check: Linux / upgrade
  • GitHub Check: Linux
🔇 Additional comments (3)
integrations/cli/index.test.ts (3)

6-6: LGTM!

The retryAssertion import is correctly added and appropriately used in the new watch mode tests to handle asynchronous file system operations.


823-844: Good test coverage for the source map bug fix.

The new watch mode tests comprehensively validate both inline and separate source map scenarios, covering the exact issues reported in #19362:

  • Initial build source map generation
  • Source map updates after file changes
  • Both --map (inline) and --map <file> (external) modes

Once the expectation values are corrected per the duplicate comments, these tests will properly prevent regression.


1000-1004: Unable to verify without test execution results.

The script confirms lines 1003 and 1027 match the snippet shown. However, determining whether these assertions are incorrect requires either:

  1. Test execution output showing what map.at() actually returns, or
  2. Understanding the code logic that generates these source map values

The current assertions show an inconsistent pattern: most map.at(4, 0) calls expect '}...', while a few expect expanded strings like '}\n.underli...' or '}\n.w-auto...'. Without CI test results or code analysis, I cannot confirm if lines 1003 and 1027 need adjustment.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28670a9 and 068a1ec.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • integrations/cli/index.test.ts (1 hunks)
  • packages/@tailwindcss-cli/src/commands/build/index.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/@tailwindcss-cli/src/commands/build/index.ts (1)
packages/@tailwindcss-node/src/source-maps.ts (1)
  • toSourceMap (44-59)
🪛 GitHub Check: Linux / cli
integrations/cli/index.test.ts

[failure] 1145-1145: cli/index.test.ts > Standalone CLI > watch mode + separate source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:1145:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > Standalone CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > Standalone CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > Standalone CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 1145-1145: cli/index.test.ts > CLI > watch mode + separate source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:1145:28
❯ utils.ts:453:14


[failure] 1145-1145: cli/index.test.ts > CLI > watch mode + separate source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:1145:28
❯ utils.ts:453:14


[failure] 1145-1145: cli/index.test.ts > CLI > watch mode + separate source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:1145:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14


[failure] 919-919: cli/index.test.ts > CLI > watch mode + inline source maps
AssertionError: expected { source: null, …(2) } to match object { source: null, …(2) }

  • Expected
  • Received

    {

  • "generated": "}
  • .underli...",
  • "generated": "}...",
    "original": "(none)",
    "source": null,
    }

❯ cli/index.test.ts:919:28
❯ utils.ts:453:14

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Linux / upgrade
  • GitHub Check: Linux
🔇 Additional comments (2)
packages/@tailwindcss-cli/src/commands/build/index.ts (2)

324-325: Use toSourceMap in watch rebuilds for consistent map handling

Wrapping compiler.buildSourceMap() with toSourceMap(…) in both full and incremental watch rebuilds aligns the watch paths with the expectations of write(…) (raw + inline) and with the initial-build behavior. This should prevent malformed or undefined map data from being appended inline or written to files during --watch rebuilds.

Also applies to: 349-350


392-395: Consistent toSourceMap usage for initial build source maps

Using toSourceMap(compiler.buildSourceMap()) inside handleError for the initial build ensures the source map always conforms to the SourceMap shape expected downstream, and keeps error handling behavior unchanged.

@thecrypticace thecrypticace merged commit 0e8f075 into main Nov 25, 2025
7 checks passed
@thecrypticace thecrypticace deleted the fix/issue-19362 branch November 25, 2025 17:23
@RV7PR
Copy link

RV7PR commented Dec 9, 2025

@thecrypticace It tried the @insiders but the problem still exists.

bun install tailwindcss@insiders @tailwindcss/cli@insiders @tailwindcss/typography@insiders                                      
bun add v1.3.4 (5eb2145b)

installed tailwindcss@0.0.0-insiders.164194d
installed @tailwindcss/cli@0.0.0-insiders.164194d with binaries:
 - tailwindcss
installed @tailwindcss/typography@0.0.0-insiders.3963dfe

[177.00ms] done
bunx @tailwindcss/cli -i ./_webblocks/css/input.css -o ./_webblocks/css/output.css --map  ./_webblocks/css/output.css.map --watch
≈ tailwindcss v4.1.17

Done in 125ms
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined

@thecrypticace
Copy link
Contributor Author

thecrypticace commented Dec 9, 2025

bunx @tailwindcss/cli … is running the latest stable version. It's not using the insiders build you installed.

If you run it with buns @tailwindcss/cli@insiders you'll see that it works.

ch4og pushed a commit to csmplay/mapban that referenced this pull request Dec 23, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [@tailwindcss/postcss](https://tailwindcss.com) ([source](https://github.com/tailwindlabs/tailwindcss/tree/HEAD/packages/@tailwindcss-postcss)) | [`4.1.17` -> `4.1.18`](https://renovatebot.com/diffs/npm/@tailwindcss%2fpostcss/4.1.17/4.1.18) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@tailwindcss%2fpostcss/4.1.18?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@tailwindcss%2fpostcss/4.1.17/4.1.18?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>tailwindlabs/tailwindcss (@&#8203;tailwindcss/postcss)</summary>

### [`v4.1.18`](https://github.com/tailwindlabs/tailwindcss/blob/HEAD/CHANGELOG.md#4118---2025-12-11)

[Compare Source](tailwindlabs/tailwindcss@v4.1.17...v4.1.18)

##### Fixed

- Ensure validation of `source(…)` happens relative to the file it is in ([#&#8203;19274](tailwindlabs/tailwindcss#19274))
- Include filename and line numbers in CSS parse errors ([#&#8203;19282](tailwindlabs/tailwindcss#19282))
- Skip comments in Ruby files when checking for class names ([#&#8203;19243](tailwindlabs/tailwindcss#19243))
- Skip over arbitrary property utilities with a top-level `!` in the value ([#&#8203;19243](tailwindlabs/tailwindcss#19243))
- Support environment API in `@tailwindcss/vite` ([#&#8203;18970](tailwindlabs/tailwindcss#18970))
- Preserve case of theme keys from JS configs and plugins ([#&#8203;19337](tailwindlabs/tailwindcss#19337))
- Write source maps correctly on the CLI when using `--watch` ([#&#8203;19373](tailwindlabs/tailwindcss#19373))
- Handle special defaults (like `ringColor.DEFAULT`) in JS configs ([#&#8203;19348](tailwindlabs/tailwindcss#19348))
- Improve backwards compatibility for `content` theme key from JS configs ([#&#8203;19381](tailwindlabs/tailwindcss#19381))
- Upgrade: Handle `future` and `experimental` config keys ([#&#8203;19344](tailwindlabs/tailwindcss#19344))
- Try to canonicalize any arbitrary utility to a bare value ([#&#8203;19379](tailwindlabs/tailwindcss#19379))
- Validate candidates similarly to Oxide ([#&#8203;19397](tailwindlabs/tailwindcss#19397))
- Canonicalization: combine `text-*` and `leading-*` classes ([#&#8203;19396](tailwindlabs/tailwindcss#19396))
- Correctly handle duplicate CLI arguments ([#&#8203;19416](tailwindlabs/tailwindcss#19416))
- Don’t emit color-mix fallback rules inside `@keyframes` ([#&#8203;19419](tailwindlabs/tailwindcss#19419))
- CLI: Don't hang when output is `/dev/stdout` ([#&#8203;19421](tailwindlabs/tailwindcss#19421))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4xNC4yIiwidXBkYXRlZEluVmVyIjoiNDIuMTQuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://git.csmpro.ru/csmpro/mapban/pulls/74
Co-authored-by: Renovate Bot <renovate@csmpro.ru>
Co-committed-by: Renovate Bot <renovate@csmpro.ru>
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.

v4 CLI: --watch --map appends "undefined" to output; --map <file> triggers TypeError [ERR_INVALID_ARG_TYPE]

2 participants