Skip to content

[AssetMapper] Import-Polyfill throws error in JS-Console. #52783

Closed
@Chris53897

Description

@Chris53897

Symfony version(s) affected

6.4.0

Description

Relates to #52547

I could not find a way to make the polyfill for importmap work.

I am aware that the behaviour changed between 6.3 and 6.4.
https://symfony.com/doc/6.4/frontend/asset_mapper.html#framework-asset-mapper-importmap-polyfill

In 6.3 i used the files from here.
// https://ga.jspm.io/npm:es-module-shims@1.8.0/dist/es-module-shims.js
// https://ga.jspm.io/npm:es-module-shims@1.8.0/dist/es-module-shims.js.map

These files do not have the problematic last line from the lastest shim.
export{t as default};
Is this because of the /+esm

a) No shim: Works

framework:
    asset_mapper:
        importmap_polyfill: false 

b) Per Default (not setting importmap_polyfill) the shim is the 1.8.2 (or actual version) from CDN.
https://cdn.jsdelivr.net/npm/es-module-shims@1.8.2/+esm

framework:
    asset_mapper:
        ...

But with this i get this error in the browser js console.
es-module-shims.index-e76dd15dae6b25cfe767df2e7fe0ec9e.js:7 Uncaught SyntaxError: Unexpected token 'export' (at es-module-shims.index-e76dd15dae6b25cfe767df2e7fe0ec9e.js:7:33789)

c) Default suggested installation (same result as b) )
php bin/console importmap:require es-module-shims

framework:
    asset_mapper:
        importmap_polyfill: 'es-module-shims'

d) WORKS: Use my local files from Symfony 6.3 and copy them into /assets/lib/es-module-shims/
// https://ga.jspm.io/npm:es-module-shims@1.8.0/dist/es-module-shims.js
// https://ga.jspm.io/npm:es-module-shims@1.8.0/dist/es-module-shims.js.map

Run:
php bin/console importmap:require "es-module-shims" --path=./assets/lib/es-module-shims/es-module-shims.js

framework:
    asset_mapper:
        importmap_polyfill: 'es-module-shims'

importmap.php

'es-module-shims' => [
        'path' => './assets/lib/es-module-shims/es-module-shims.js',
    ],```


### How to reproduce

See above

### Possible Solution

_No response_

### Additional Context

_No response_

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions