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

Uncaught TypeError: Color is not a constructor #98

Closed
none511 opened this issue Jun 11, 2021 · 6 comments
Closed

Uncaught TypeError: Color is not a constructor #98

none511 opened this issue Jun 11, 2021 · 6 comments
Assignees
Labels
bug Something isn't working Topic: build process

Comments

@none511
Copy link

none511 commented Jun 11, 2021

including the library in "classic way":

<script src="https://colorjs.io/dist/color.js"></script>

gives Uncaught TypeError: Color is not a constructor

@Artoria2e5
Copy link
Contributor

Artoria2e5 commented Jun 14, 2021

Try using Color.default. It's a transpiled ESM thing now. Tell me if it works or not, so I can do a doc PR accordingly.

@LeaVerou
Copy link
Member

LeaVerou commented Jun 17, 2021

Confirmed.

Testcase (copy and paste in URL bar):

data:text/html;charset=utf8,<script src="https://colorjs.io/dist/color.js"></script><script>new Color("purple")</script>

Could possibly be a Rollup bug.

@LeaVerou
Copy link
Member

Try using Color.default. It's a transpiled ESM thing now. Tell me if it works or not, so I can do a doc PR accordingly.

Thanks for the workaround, but I consider this a bug on our end. People who want to use the IIFE bundle should not have to know or care about ESM, this looks like a leaky abstraction. If it's impossible to build it properly with Rollup, perhaps a custom Node script to transform the Rollup output might work. But it seems strange if Rollup can't do this.

@LeaVerou LeaVerou added bug Something isn't working Topic: build process labels Jun 17, 2021
@svgeesus
Copy link
Member

This bit me again today

@gerardnico
Copy link

Me too. Thanks for the documentation !

@musagenius345
Copy link

Same thing happens with node REPL, I had to

const Color = require('colorjs.io') const colorObj = Color.default let green = new colorObj('green') .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Topic: build process
Projects
None yet
Development

No branches or pull requests

6 participants