fix(misc): use default import for chalk in @nx/workspace output.ts#35523
Open
jdgarvey wants to merge 1 commit intonrwl:masterfrom
Open
fix(misc): use default import for chalk in @nx/workspace output.ts#35523jdgarvey wants to merge 1 commit intonrwl:masterfrom
jdgarvey wants to merge 1 commit intonrwl:masterfrom
Conversation
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
👷 Deploy request for nx-dev pending review.Visit the deploys page to approve it
|
tslib's __importStar only copies own enumerable properties; chalk v4 puts reset/bold/etc on the prototype, so chalk.reset becomes undefined after wrapping — crashing any code that requires @nx/workspace. esModuleInterop:true was added in nrwl#34111 (commit 732a08c), causing `import * as chalk` to emit __importStar in compiled output and expose this latent bug. fix: change to default import (`import chalk from 'chalk'`) which compiles to __importDefault().default, preserving chalk's prototype chain. same root cause fixed previously in: - nrwl#21201 (@nx/eslint-plugin) - nrwl#26667 (@nx/angular) Fixes nrwl#35521
8b201b0 to
ad3b642
Compare
markgoho
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
require('@nx/workspace')throws aTypeErrorin 22.7.x, crashing any generator that imports from@nx/workspace:Fixes #35521
Root Cause
PR #34111 (commit
732a08c) addedesModuleInterop: truetotsconfig.base.json. This causedimport * as chalk from 'chalk'inoutput.tsto compile totslib.__importStar(require("chalk"))instead ofrequire("chalk")directly.tslib.__importStaronly copies own enumerable properties — chalk v4 exposesreset,bold,inverse, etc. as prototype getters on theChalkclass, not own properties. After wrapping,chalk.resetisundefined→ crash.Changes
packages/workspace/src/utils/output.ts— changeimport * as chalk from 'chalk'toimport chalk from 'chalk'.With
esModuleInterop: true, the default import compiles to__importDefault(require("chalk")).defaultwhich returns the chalk instance directly with its prototype chain intact.How Has This Been Tested?
Same fix applied previously for the identical root cause in:
@nx/eslint-plugin)@nx/angular)Verified by simulating the compiled output in a minimal repro workspace — see #35521 for the reproduction script.
Checklist
nx affected:testhas been run