fitty icon indicating copy to clipboard operation
fitty copied to clipboard

fitty_module is not a function

Open smth opened this issue 5 years ago • 8 comments

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?

smth avatar Jul 29 '20 17:07 smth

what if you do import fitty from 'fitty/dist/fitty.module.js'

rikschennink avatar Jul 31 '20 06:07 rikschennink

Same result.

smth avatar Jul 31 '20 07:07 smth

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.

PaulMorel avatar Aug 03 '20 03:08 PaulMorel

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');

smth avatar Aug 03 '20 08:08 smth

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 avatar Aug 03 '20 10:08 rikschennink

@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 avatar Aug 03 '20 13:08 PaulMorel

@PaulMorel thanks, will look into it when I have some free time

rikschennink avatar Aug 18 '20 16:08 rikschennink

Just tested with codesandbox but seems to work fine: https://codesandbox.io/s/fitty-demo-bzkfb?file=/src/index.js

rikschennink avatar Sep 09 '20 07:09 rikschennink