Open ivansenic opened 5 years ago
Seems that something is wrong with the type definitions (at least with the setup we are using). When I change the types/index.d.ts
to export functions as:
export default {
init(pixelId: string, advancedMatching?: AdvancedMatching, options?: Options): void,
pageView(): void,
track(title: string, data: Data | any): void,
trackCustom(title: string, data: Data | any): void
}
then everything works when I import it via import ReactPixel from 'react-facebook-pixel';
. I assume this is because the functions in the .js
are grouped in the object which is exported as default..
The only workaround we are aware of in the moment is to import the .js
file directly and lose the typing:
const ReactPixel = require('react-facebook-pixel').default
But this requires us also to disable the no-var-requires
lint rule.
All in all this seems as a bug to me? Could you confirm?
I'm having this problem as well. I was thinking about declaring the init elsewhere and then calling it.
I cannot believe there is this little documentation on this!
Can you please try
import ReactPixel from 'react-facebook-pixel';
Can you please try
import ReactPixel from 'react-facebook-pixel';
Fails with:
Module '\"../node_modules/react-facebook-pixel/types/index\"' has no default export.
~This was our workaround:~
~import { Data, init, pageView, track, trackCustom } from 'react-facebook-pixel';
~
Above workaround is terribly wrong.
I have this issue as well. Is there a workaround, or @zsajjad can you fix?
@dblarons I have this issue too. Use import ReactPixel from 'react-facebook-pixel/src/index';
its work for me
const ReactPixel = require('react-facebook-pixel').default
This looks to be the same thing I've had to do. Definitely a bummer to lose the typing.
same issue... damn
same, how long will this be until it get solved?
I got the same problem as it seems to me I can import it such as follow
import {init, pageView} from 'react-facebook-pixel'
Because it's so bad for lighthouse to report 93% of unused code from connect.facebook.net. Better to get rid of them. But when I import it like that I get the error, which sucks
const ReactPixel = require('react-facebook-pixel').default
this seemed to work for me
Hi,
We are trying to install this in our React web app, but hitting the error mentioned below. We are using typescript and importing with
import * as ReactPixel from 'react-facebook-pixel';
. The code compiles successfully, but on the runtime we hit the error.We created a wrapper for any page in exact same way as we did for the ReactGA using the hooks (full code also below).
Any idea what I am doing wrong? Does anyone has any experience with using the module with typescript?
Thanks in advance..