Pomax / lib-font

This library adds a new Font() object to the JavaScript toolbox, similar to new Image() for images
MIT License
728 stars 72 forks source link

Prebuilt `lib-font.browser.js` bundle throws `Unexpected token 'export'` error #131

Closed nuthinking closed 2 years ago

nuthinking commented 2 years ago

When loaded or embedded as a simple script (not module) it throws: lib-font.browser.js:1 Uncaught SyntaxError: Unexpected token 'export' (at lib-font.browser.js:1:81241)

Pomax commented 2 years ago

The README.md explicitly calls this out: https://github.com/Pomax/lib-font#tddr

nuthinking commented 2 years ago

Ops, I thought that because it was a bundle it didn't need to be a module. Sorry about that!

nuthinking commented 2 years ago

@Pomax if I add the type attribute as module I then get: Failed to resolve module specifier 'zlib'. Thanks!

Pomax commented 2 years ago

Heh, also called out in the README.md but probably not as obvious: https://github.com/Pomax/lib-font#why-dont-woffwoff2 since browsers (frustratingly) don't come with a convenient Compression object even though they fully support deflate/inflate, zip/unzip, and brotli/unbrotli because of server compression, so there's two helper libraries that you can load.

For "complete" functionality:

<!doctype html>
<html>
    <head>
        ...
        <script src=".../lib/inflate.js" defer></script>
        <script src=".../lib/unbrotli.js" defer>script>
        <!-- and then make index import from "lib-font.browser.js" -->
        <script src=".../index.js" type="module" async></script>
    </head>
    <body>
        ...
    </body>
</html>