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

[Bug] import_coloris.default.init is not a function #59

Closed
jjf21 opened this issue Apr 5, 2022 · 14 comments · Fixed by #60
Closed

[Bug] import_coloris.default.init is not a function #59

jjf21 opened this issue Apr 5, 2022 · 14 comments · Fixed by #60
Assignees
Labels
bug Something isn't working

Comments

@jjf21
Copy link

jjf21 commented Apr 5, 2022

I have same kind of errors as #13

Just by adding

import "@melloware/coloris/dist/coloris.css";
import Coloris from "@melloware/coloris";
Coloris.init();
Coloris({el: "#coloris"});

I have the error:

Uncaught TypeError: import_coloris.default.init is not a function

Using CDN is working properly, am I missing something ?

@jjf21 jjf21 added the enhancement New feature or request label Apr 5, 2022
@melloware
Copy link
Owner

Are you using the latest version 0.10.3 ?

@melloware melloware added bug Something isn't working and removed enhancement New feature or request labels Apr 5, 2022
@jjf21
Copy link
Author

jjf21 commented Apr 5, 2022

Yes

"@melloware/coloris": "^0.10.3"

Small project, here is the package.json

    "@hotwired/stimulus": "^3.0.1",
    "@hotwired/turbo-rails": "^7.1.1",
    "@melloware/coloris": "^0.10.3",
    "autoprefixer": "^10.4.4",
    "esbuild": "^0.14.27",
    "feather-icons": "^4.28.0",
    "postcss": "^8.4.12",
    "puppeteer": "^13.5.2",
    "tailwindcss": "^3.0.23"

@melloware
Copy link
Owner

@blutorange this cropped up again but all of our tests are passing where you basically check this.

@melloware
Copy link
Owner

The last time this happened we added this test case which runs on build: https://github.com/melloware/coloris-npm/blob/main/test-npm/webpack-ts/src/index.ts

@jjf21
Copy link
Author

jjf21 commented Apr 5, 2022

Is there any manual configuration I can try to help find out the problem ?

@blutorange
Copy link
Collaborator

blutorange commented Apr 5, 2022

The test works because of this entry in the tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
  }
}

The UMD wrapper has

module.exports.Coloris = factory();

where factory() is the Coloris function/object. So with plain commonJS , that would be const {Coloris} = require("@melloware/coloris") or import {Coloris} from "@melloware/coloris"; for ESM

Can't quite remember why we didn't make that module.exports = factory();, but I suppose it was because otherwise it'd be incompatible with some parts of the ecosystem (TS, other module systems etc.)

@blutorange
Copy link
Collaborator

I think it may have been (at least partially) due to AMD / requirejs support. At any rate, changing that right now would probably result in issues for people already using this lib. So for now, I'd say we should just update the docs and re-evaluate whether we want to change the module wrapper with the next major release of Coloris.

@melloware
Copy link
Owner

I am ok with breaking this wrapper to get it right. We only have about 80 downloads a week and increasing each month. Better to fix it for good sooner than later?

@blutorange
Copy link
Collaborator

blutorange commented Apr 5, 2022

Hmm ok, but I need to think about whether that is right or not. Default exports are a problem by themselves and may work differently depending on the bundler / module system. I might have some time during the next few days. I guess we should start by adding more a few tests with webpack and other bundlers, with / without TS.

@melloware
Copy link
Owner

Ok no worries. You are the expert!

blutorange added a commit to blutorange/coloris-npm that referenced this issue Apr 9, 2022
blutorange added a commit to blutorange/coloris-npm that referenced this issue Apr 9, 2022
melloware pushed a commit that referenced this issue Apr 9, 2022
* Add more tests, define module directly on module.exports, update readme, #59

* Support ESM #59
@jjf21
Copy link
Author

jjf21 commented Apr 9, 2022

Hi, thanks for your work but it is still not working.

Even with:

import "@melloware/coloris/dist/coloris.css";
import { coloris, init } from "@melloware/coloris";
init();
coloris({el: "#coloris"});

@blutorange
Copy link
Collaborator

blutorange commented Apr 10, 2022

@jjf21 Could you share a simple project that illustrates the issue? Might be specific to whatever bundler etc. you are using. Also, did you test against the current version in this github repo since I believe there was no release yet with the change (so the coloris export doesn't exist yet)?

@blutorange
Copy link
Collaborator

I uploaded version 0.10.4-rc1 to npm if you want to try.

@jjf21
Copy link
Author

jjf21 commented Apr 10, 2022

In fact I tried it with

yarn add ssh://git@github.com:melloware/coloris-npm.git#main

using 0.10.4-rc1 works perfectly !

Thanks for your help !

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

Successfully merging a pull request may close this issue.

3 participants