Skip to content

Replace static chalk require with dynamic import#45

Merged
jaseel0 merged 2 commits intoindexfrom
copilot/sub-pr-44
Mar 4, 2026
Merged

Replace static chalk require with dynamic import#45
jaseel0 merged 2 commits intoindexfrom
copilot/sub-pr-44

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

chalk v5+ is ESM-only; the top-level const chalk = require("chalk") will break on upgrade. This replaces it with dynamic imports scoped to each action handler, consistent with how ora is already imported.

Changes

  • bin/index.js
    • Removed top-level const chalk = require("chalk")
    • Added const { default: chalk } = await import("chalk") inside the run command's async action alongside the existing ora import
    • Made analyze command action async and added the same dynamic chalk import
// Before
const chalk = require("chalk");
// ...
.action(async (file) => {
  const { default: ora } = await import("ora");
  // chalk already in scope via top-level require

// After
.action(async (file) => {
  const { default: ora } = await import("ora");
  const { default: chalk } = await import("chalk");

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Add --json option and improve CLI output Replace static chalk require with dynamic import Mar 4, 2026
@jaseel0 jaseel0 marked this pull request as ready for review March 4, 2026 05:03
@github-actions github-actions bot added the cli label Mar 4, 2026
@jaseel0
Copy link
Collaborator

jaseel0 commented Mar 4, 2026

@copilot fix this to
chalk.bold.cyan(\n🚀 ErrLens Analysis (${count} Issue(s)):)
^

TypeError: Cannot read properties of undefined (reading 'cyan')
at Command. (C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\bin\index.js:135:20)
at Command.listener [as _actionHandler] (C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\node_modules\commander\lib\command.js:568:17)
at C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\node_modules\commander\lib\command.js:1604:14
at Command._chainOrCall (C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\node_modules\commander\lib\command.js:1488:12)
at Command._parseCommand (C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\node_modules\commander\lib\command.js:1603:27)
at C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\node_modules\commander\lib\command.js:1367:27
at Command._chainOrCall (C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\node_modules\commander\lib\command.js:1488:12)
at Command._dispatchSubcommand (C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\node_modules\commander\lib\command.js:1363:25)
at Command._parseCommand (C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\node_modules\commander\lib\command.js:1559:19)
at Command.parse (C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\node_modules\commander\lib\command.js:1093:10)

C:\Users\Dell\Desktop\New folder\javascript>errlens run test.js
C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\bin\index.js:30
: ora(Running ${chalk.yellow(file)}...).start();
^

TypeError: chalk.yellow is not a function
at Command. (C:\Users\Dell\AppData\Roaming\npm\node_modules\errlens\bin\index.js:30:30)

Node.js v22.18.0

C:\Users\Dell\Desktop\New folder\javascript>errlens run test.js

Copy link
Contributor Author

Copilot AI commented Mar 4, 2026

@copilot fix this to
chalk.bold.cyan(\n🚀 ErrLens Analysis (${count} Issue(s)):)
^
...

The current implementation (from commit 86e30f0) correctly uses const { default: chalk } = await import("chalk") in both action handlers, which ensures chalk is the actual chalk instance. This makes chalk.bold.cyan(...) work correctly — as confirmed by testing both analyze and run commands against the matching code path. The TypeError you described would occur if chalk were imported without destructuring default (i.e., const chalk = await import("chalk") gives the module namespace, where chalk.bold is undefined), but the current code destructures it properly.

@jaseel0 jaseel0 merged commit b7833a6 into index Mar 4, 2026
2 checks passed
@jaseel0 jaseel0 deleted the copilot/sub-pr-44 branch March 4, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants