question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to import in NodeJS?

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
mutluhanuzmezcommented, Oct 21, 2021

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.

0reactions
mattvb91commented, May 6, 2022

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>
    </>
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting started with Node.js modules: require, exports, imports ...
Imports. Starting with version 8.5.0+, Node.js supports ES modules natively with a feature flag and new file extension *.mjs ...
Read more >
How to use an ES6 import in Node.js? - GeeksforGeeks
Introduction to ES6 import: The import statement is used to import modules that are exported by some other module. A module is a...
Read more >
import - JavaScript - MDN Web Docs - Mozilla
The static import declaration is used to import read-only live bindings which are exported by another module. The imported bindings are ...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
An import statement can reference an ES module or a CommonJS module. import statements are permitted only in ES modules, but dynamic import()...
Read more >
How to use the “import” statement in Node.js | by Tirlochan Arora
If you have used other JavaScript frameworks like React or Vue.js, then you know that these frameworks use the “import” keyword for importing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found