Skip to content

Cannot build TypeScript due to use of chalk v5.0.0 #46930

Closed
@uhyo

Description

@uhyo

🚧 DO NOT POST HERE to report breakage of your project! 🚧

This issue is specific to the TypeScript project itself and is already closed.

If your build is broken due to chalk and you are looking for a solution, READ THIS.


Bug Report

TL; DR

Chalk released 5.0.0 21 hours ago which is now a Pure ESM module. TypeScript depends on the latest version of chalk, but is incompatible with the ESM version.

We have two options:

  • Explicitly depend on chalk 4.x.
  • Fix our script to work with chalk 5.0.

🔎 Search Terms

chalk ERR_REQUIRE_ESM

🕗 Version & Regression Information

main

⏯ Playground Link

N/A

💻 Code

npm install
npx gulp watch-tsc`

🙁 Actual behavior

npm install, npx gulp watch-tsc or any other attempt to build TypeScript fails with following error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/TypeScript/node_modules/chalk/source/index.js
require() of ES modules is not supported.
require() of /path/to/TypeScript/node_modules/chalk/source/index.js from /path/to/personal/TypeScript/scripts/build/utils.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /path/to/TypeScript/node_modules/chalk/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/path/to/TypeScript/scripts/build/utils.js:11:15)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
  code: 'ERR_REQUIRE_ESM'
}

🙂 Expected behavior

Successfully builds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions