Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chalk 5.x fails with typescript #613

Closed
drernie opened this issue Sep 16, 2023 · 3 comments
Closed

chalk 5.x fails with typescript #613

drernie opened this issue Sep 16, 2023 · 3 comments

Comments

@drernie
Copy link

drernie commented Sep 16, 2023

The current 5.x version of chalk does not appear to work with typescript.
Here is an example project that works great with v4.x, but fails catastrophically when upgrading to 5.x:

TheSwanFactory/ts-cli#5
https://github.com/TheSwanFactory/ts-cli/tree/5-chalk-5x-fails-with-typescript

@drernie
Copy link
Author

drernie commented Sep 16, 2023

The error message is:

const chalk = require("chalk");
              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/ernest/Developer/ts-cli/node_modules/chalk/source/index.js from /Users/ernest/Developer/ts-cli/dist/src/utils.js not supported.
Instead change the require of index.js in /Users/ernest/Developer/ts-cli/dist/src/utils.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/ernest/Developer/ts-cli/dist/src/utils.js:14:15)
    at Object.<anonymous> (/Users/ernest/Developer/ts-cli/dist/src/index.js:4:17) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.5.1

This is from the generated JavaScript. The original TypeScript uses:

import * as chalk from "chalk";

I can't find any combination that does work.

@drernie
Copy link
Author

drernie commented Sep 16, 2023

I suppose this may be a TypeScript issue, but they appear to have punted:

microsoft/TypeScript#46930

This issue appears to be well-known on the Internet, but apparently nobody filed a ticket before ;-{

I will look into the ESM discussion to see if that helps...

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

@drernie
Copy link
Author

drernie commented Sep 16, 2023

Oh, I guess this issue came up before, sorry:

#527

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

No branches or pull requests

1 participant