You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The crash course shows an example with using import to get different functions from ansicolor. However, ESModules don't work that way, and currently you cannot do
Instead, you'd have to import the entire class, like this.
importansiColorfrom'ansicolor'ansiColor.green()
This is because the build/ansicolor.js is a commonjs file, which only has a default export. There are no named exports, so the invalid example above doesn't work.
What needs to be fixed
So first, the README.md file needs to be changed to provide valid code.
I hope that there can be a new feature which has an ESModule file. The file can have named exports like green, red, and all the other static functions.
The text was updated successfully, but these errors were encountered:
Hey, it seems to be fixed thanks to the effort of @rayfoss — he's made a dual mode package support so native ESM imports now work for ansicolor. Check it out.
Actually, the example code meant to be used with esm loader or transpilers that handle named imports from commonjs modules. And I've never checked if it works with native Node's ESM support — my fault. But now it seems to be resolved.
What's Inaccurate
The crash course shows an example with using
import
to get different functions fromansicolor
. However, ESModules don't work that way, and currently you cannot doInstead, you'd have to import the entire class, like this.
This is because the
build/ansicolor.js
is a commonjs file, which only has adefault
export. There are no named exports, so the invalid example above doesn't work.What needs to be fixed
README.md
file needs to be changed to provide valid code.green
,red
, and all the other static functions.The text was updated successfully, but these errors were encountered: