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

Inaccurate Example In README Crash Course #12

Closed
ChocolateLoverRaj opened this issue Sep 22, 2020 · 1 comment
Closed

Inaccurate Example In README Crash Course #12

ChocolateLoverRaj opened this issue Sep 22, 2020 · 1 comment

Comments

@ChocolateLoverRaj
Copy link

What's Inaccurate

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

import { green } from 'ansicolor' // Doesn't work

green()

Instead, you'd have to import the entire class, like this.

import ansiColor from '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.
@xpl
Copy link
Owner

xpl commented Jun 18, 2021

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.

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

2 participants