chalk/supports-color

Change to ESM causes backwards compatibility issues #116

yinzara posted onGitHub

The cordova-webpack-plugin depends on supports-color. All versions 8.1.1 and earlier work fine with the plugin however when upgrading to supports-color 9.0.0 I get the following error:

require() of /pathto/mycordovaproject/node_modules/supports-color/index.js from /pathto/mycordovaproject/plugins/cordova-plugin-webpack/dist/options/webpack.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 /pathto/mycordovaproject/node_modules/supports-color/package.json.

I think the issue is that supports-color now ONLY supports ESM syntax (it doesn't provide a hybrid configuration to allow for both). I think this is probably going to cause a lot of problems with a lot of people upgrading to this version.

It might be a better solution to add a babel compilation step to create a CJS version of the library and then configure that appropriately in the package.json so that either ESM or CJS imports function correctly.

https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html - this gives some information about using TypeScript as the transpiler but you could replace it with Babel in CJS configuration as well so you don't have to convert the project to typescript.

posted by yinzara almost 4 years ago

Took me a bit too long to find out why this was closed (Bug->PR->Tag->Release Notes->Gist), so here's the direct link for latecomers: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

P.S. Takk for et nyttig bibliotek fra gjengen i Sinon.

posted by fatso83 almost 4 years ago

I think this is probably going to cause a lot of problems with a lot of people upgrading to this version.

Probably. That's why it's a major version. This shouldn't be a surprise to anyone. Please see https://semver.org/.

And no, we won't be doing any Babel compilation. That's a dead era.

posted by Qix- almost 4 years ago

hello, follow up to this warning, its now a error in node

node v23.1.0

 ERROR  (node:31318) ExperimentalWarning: CommonJS module /home/mirsella/dev/hypertube/node_modules/.pnpm/debug@4.3.7_supports-color@9.4.0/node_modules/debug/src/node.js is loading ES Module /home/mirsella/dev/hypertube/node_modules/.pnpm/supports-color@9.4.0/node_modules/supports-color/index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
posted by mirsella 5 months ago

That has nothing to do with chalk, that's a known debug issue (hence /home/mirsella/dev/hypertube/node_modules/.pnpm/debug).

Please see https://github.com/debug-js/debug/issues/975.

Marking these as off-topic since it's unrelated to this issue.

posted by Qix- 5 months ago

Fund this Issue

$0.00
Funded

Pull requests