lukeed / tsm

TypeScript Module Loader
MIT License
1.18k stars 19 forks source link

Bug when using tsm with chalk 5.0.0 #31

Closed leonsilicon closed 1 year ago

leonsilicon commented 2 years ago

First of all, thanks for this amazing project!

I noticed that tsm fails to import dependencies from chalk 5, giving the following error:

(node:41021) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:41021) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getFormat, transformSource
file:///Users/leonzalion/projects/tsm-bug/node_modules/.pnpm/chalk@5.0.0/node_modules/chalk/source/index.js#supports-color.mts:26
const { stdout: stdoutColor, stderr: stderrColor } = supportsColor;
                ^

TypeError: Cannot destructure property 'stdout' of 'supportsColor' as it is undefined.
    at file:///Users/leonzalion/projects/tsm-bug/node_modules/.pnpm/chalk@5.0.0/node_modules/chalk/source/index.js#supports-color.mts:26:17
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

It seems like the chalk supportsColor import is becoming undefined, and I believe it has something to do with how chalk imports its dependencies:

import ansiStyles from '#ansi-styles';
import supportsColor from '#supports-color';

Here is a GitHub repo that reproduces this error: https://github.com/leonzalion/tsm-bug Node version: 16.13.2

Let me know if this is a tsm bug and/or if there's a workaround to this issue!

GuilleDF commented 2 years ago

I'm getting the same issue when using https://github.com/sindresorhus/ora since it has chalk as a dependency

btakita commented 2 years ago

Also getting this issue. I used a package.json pnpm.override to "chalk": "4.1.2" to work around this problem.

BasixKOR commented 2 years ago

It seems like tsm doesn't support subpath imports yet?

azat-io commented 1 year ago

Same issue

karlhorky commented 1 year ago

Created a Replit for this here:

https://replit.com/@karlhorky/tsm-chalk-5-example#package.json

This confirms that the problem is also present with an updated esbuild@0.14.54, which is the latest version of esbuild matching tsm's semver range:

https://github.com/lukeed/tsm/blob/2fd630db070625c64cd2b10d49700c942e12105e/package.json#L36

azat-io commented 1 year ago

Same error with tsm v2.3.0

(node:42830) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:42830) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getFormat, transformSource
/Users/user/Developer/azat-io/node_modules/.pnpm/chalk@5.1.2/node_modules/chalk/source/index.js:8
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
               ^

TypeError: Cannot destructure property 'stdout' of 'supportsColor' as it is undefined.
    at <anonymous> (/Users/user/Developer/azat-io/node_modules/.pnpm/chalk@5.1.2/node_modules/chalk/source/index.js:8:16)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v19.1.0