fitty
fitty copied to clipboard
fitty_module is not a function
Hi
I'm getting TypeError: fitty_module is not a function when using Fitty with Rollup.
I'm doing this:
import fitty from 'fitty'
fitty('.my-element');
My Rollup config is essentially this.
What am I doing wrong?
what if you do import fitty from 'fitty/dist/fitty.module.js'
Same result.
I made it work like this with Rollup
import fitty from 'fitty';
window.fitty = fitty.default;
// Do your thing
fitty('.my-element');
I don't 100% understand all the various ways to import and export modules, but from my understainding the default export seems to be an object and within the default key of that object, we have the fitty() function as the value.
That resulted in the same error for me, but did prompt me to try the below, which seems to work. :+1:
import fitty from 'fitty';
fitty.default('.my-element');
Okay, nice, happy to make adjustments to the package.json to get this working, but not sure why this happens. Will leave the issue open for any suggestions.
@rikschennink From a quick observation, it seems like it might be due to an older version of Babel? I tried transpiling the source using Babel v7.11.0 and the resulting file is different. In this case fitty gets assigned to a global _default var instead of being assigned to exports.default. If we give the exported function a name, it should be available as a global variable other than _default.
I haven't had the time to test this thoroughly, but I think it's a good lead.
@PaulMorel thanks, will look into it when I have some free time
Just tested with codesandbox but seems to work fine: https://codesandbox.io/s/fitty-demo-bzkfb?file=/src/index.js