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

Change to ESM causes backwards compatibility issues #116

Closed
yinzara opened this issue Apr 21, 2021 · 5 comments
Closed

Change to ESM causes backwards compatibility issues #116

yinzara opened this issue Apr 21, 2021 · 5 comments

Comments

@yinzara
Copy link

yinzara commented Apr 21, 2021

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.
@yinzara
Copy link
Author

yinzara commented Apr 21, 2021

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.

@fatso83
Copy link

fatso83 commented May 11, 2021

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.

@Qix-
Copy link
Member

Qix- commented May 11, 2021

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.

@mirsella

This comment was marked as off-topic.

@Qix-

This comment was marked as off-topic.

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

Successfully merging a pull request may close this issue.

5 participants