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

0.4.3 and 0.4.4 are broken for dynamic import #41

Closed
softwarecreations opened this issue Feb 1, 2021 · 2 comments
Closed

0.4.3 and 0.4.4 are broken for dynamic import #41

softwarecreations opened this issue Feb 1, 2021 · 2 comments

Comments

@softwarecreations
Copy link

I'm dynamically importing pretty-print-json.

On versions 0.4.3 and 0.4.4 the loaded object only has a default property, which is an empty object... and has no other properties in the root object or in default.
Whereas on 0.4.2 I get this, and it works.
image

@dpilafian
Copy link
Member

Oops, sorry for breaking that. The pretty-print-json module definition was changed to be a "named" export when the library was converted to TypeScript.

The standard import now should be done with curly braces:

import { prettyPrintJson } from 'pretty-print-json';

For a dynamic import, the Promise will return a module to be used like:

const url = '/libs/pretty-print-json.esm.js';
import(url).then(module => {
   const data = [3, 7, 21];
   const html = module.prettyPrintJson.toHtml(data);
   ...
   };

Here's a page to test out dynamically loading pretty-print-json:
https://pretty-print-json.js.org/dynamic/

ES Module Dynamic Loading

@softwarecreations
Copy link
Author

Thanks bud, it's working great :)

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