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

fitty_module is not a function #61

Open
smth opened this issue Jul 29, 2020 · 8 comments
Open

fitty_module is not a function #61

smth opened this issue Jul 29, 2020 · 8 comments

Comments

@smth
Copy link

smth commented Jul 29, 2020

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?

@rikschennink
Copy link
Owner

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

@smth
Copy link
Author

smth commented Jul 31, 2020

Same result.

@PaulMorel
Copy link

PaulMorel commented Aug 3, 2020

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.

@smth
Copy link
Author

smth commented Aug 3, 2020

That resulted in the same error for me, but did prompt me to try the below, which seems to work. 👍

import fitty from 'fitty';

fitty.default('.my-element');

@rikschennink
Copy link
Owner

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.

@PaulMorel
Copy link

PaulMorel commented Aug 3, 2020

@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.

@rikschennink
Copy link
Owner

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

@rikschennink
Copy link
Owner

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

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

3 participants