jspm / generator

JSPM Import Map Generator
Apache License 2.0
166 stars 21 forks source link

Unexpected token 'export' when pulling in single-spa as a dependency #94

Closed SomethingSexy closed 2 years ago

SomethingSexy commented 2 years ago

Sorry if this is the wrong place to ask this kind of specific question. I am using this library to generate some import maps. One of the dependencies is single-spa. The package is referencing version 5.9.3. When I pipe it through the generator using these settings

    defaultProvider: 'jspm',
    env: ['production', 'browser']

I am getting this

"single-spa":"https://ga.jspm.io/npm:single-spa@5.9.3/lib/umd/single-spa.min.js"

However, at the end of that file that it is pulling down is

;export default n;

Is there a reason that is being added? I don't see that in the npm version and I am not setting the env to 'module'. Am I missing some configuration somewhere? Thanks!

SomethingSexy commented 2 years ago

I might have opened this ticket too soon. I switched the default provider to jspm.system and that seems to give me a version without the export being added.

guybedford commented 2 years ago

@SomethingSexy you're going to want to add the "module" condition in the env there and then it will use the "module" field in the package.json defined. JSPM will convert CommonJS and UMD modules into ES modules, hence it adds a default export to make them importable.

SomethingSexy commented 2 years ago

@guybedford should it add that default export at the end of the file, outside of the System.register wrapper?

guybedford commented 2 years ago

@SomethingSexy System modules aren't supported as input on JSPM - UMD modules are interepreted as CommonJS and thus given a default export. Add the "module" condition to use the correct entry point for SingleSPA.

SomethingSexy commented 2 years ago

Got it! Thanks for the explanation. I think I might have something else going on with the version of single-spa being return from JSPM vs jsdelivr but I need to investigate further. This issue can be closed. Thanks again.

guybedford commented 2 years ago

@SomethingSexy using:

    defaultProvider: 'jspm',
    env: ['production', 'browser', 'module']

should fix the issue as discussed above.