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

How to use with import in react? #5

Open
a-rbsn opened this issue Apr 28, 2022 · 4 comments
Open

How to use with import in react? #5

a-rbsn opened this issue Apr 28, 2022 · 4 comments

Comments

@a-rbsn
Copy link

a-rbsn commented Apr 28, 2022

Hey @ccprog — I'm trying to use this in a react project/nextjs but when I import and use new Pathfit(... it tells me that Pathfit isn't a constructor, I'm importing as so:

import Pathfit from "pathfit";

after installing from npm, any ideas would be appreciated!

@ccprog
Copy link
Owner

ccprog commented Apr 29, 2022

Ominously, If you search Stackoverflow for [nextjs] TypeError: is not a constructor, you get a lot of unanswered questions...

I think the most probable reason is you are importing in ECMA script module syntax, but the module is written in CommonJS syntax. Node.js sometimes needs a bit of guidance to handle these mixed format situations. As a short term remedy, you could try to include https://www.npmjs.com/package/next-transpile-modules with your nextjs configuration. It transpiles all modules just the way the Babel configuration expects them.

I'll look further into whether I can help from my side.

@ccprog
Copy link
Owner

ccprog commented Apr 29, 2022

2a3f251 adds a hint to package.json about the module format. Not sure that will help, but you can try to update to the 1.0.4 version.

@a-rbsn
Copy link
Author

a-rbsn commented May 4, 2022

@ccprog thanks for your help, unfortunately it's still not working but I'm going to have a gander today and will update here when I've eventually figured it out :)

@a-rbsn
Copy link
Author

a-rbsn commented May 6, 2022

hey @ccprog — I have found a very simple solution, I changed the rollup config to output 'umd' instead of 'cjs' or 'iife' and that output a file which I can import into react like how I wanted, I didn't want to fork just for this change but if you wanted to make that small update you know how :)

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

2 participants