iframe-resizer icon indicating copy to clipboard operation
iframe-resizer copied to clipboard

How to import in NodeJS?

Open el-pol opened this issue 3 years ago • 5 comments

I can't seem to manage to import it in NodeJS using import x from 'y'. There's nothing in the docs.

If I do: import { iframeResizer } from 'iframe-resizer' I get the error that the element is not exported.

And if I just import x I get the error that there is no default export.

el-pol avatar Jul 15 '21 17:07 el-pol

I'm having the same problem. Could you find a workaround for the issue @el-pol?

When I try import { iframeResize } from 'iframe-resizer'; I get that error, The requested module './../../../node_modules/iframe-resizer/index.js' does not provide an export named 'iframeResize'

When I try import iframeResize from 'iframe-resizer'; I get that error, SyntaxError: The requested module './../../../node_modules/iframe-resizer/index.js' does not provide an export named 'default' When I just try it import 'iframe-resizer'; ReferenceError: module is not defined

Probably I'm doing sth wrong, any help will be appreciated :)

mutluhanuzmez avatar Oct 15 '21 07:10 mutluhanuzmez

@mutluhanuzmez I got the same. I ended up giving up on this library and writing my own JS code. I'm sure it's something stupid we are missing :)

el-pol avatar Oct 20 '21 14:10 el-pol

I tried to import the js files inside of the module directly in the parent page this way and it worked. import 'iframe-resizer/js/iframeResizer';

also in the iframed page this way import 'iframe-resizer/js/iframeResizer.contentWindow';

ps: There was also another problem for me while using iFrameResize method. I was using LitElement and it was rendering in the shadow DOM. Therefore sending the target as the iframe id didn't work for me. I took the iframe ref and send it to the method.

const iframe = this.shadowRoot.querySelector('#myIframe');
iFrameResize({log: true}, iframe);

Works perfect now, but I still don't like the import this way.

mutluhanuzmez avatar Oct 21 '21 13:10 mutluhanuzmez

@mutluhanuzmez happy you solved it! This should be in the docs

el-pol avatar Oct 27 '21 13:10 el-pol

For anyone else coming here from react side of things this worked for me. Probably not ideal but for now its a workaround

import 'iframe-resizer/js/iframeResizer';
import 'iframe-resizer/js/iframeResizer.contentWindow';

const Page = () => {

    const iframe = useRef()

    useEffect(() => {
        //@ts-ignore
        iFrameResize({}, iframe.current);
    }, [])

    return <>
        <iframe
            ref={iframe}
            src="bla.com" >
        </iframe>
    </>
}

mattvb91 avatar May 06 '22 07:05 mattvb91

This will be address in v5

davidjbradshaw avatar Feb 13 '24 14:02 davidjbradshaw