stealjs / steal-tools

Build easy. Load fast.
https://stealjs.com/docs/steal-tools.html
MIT License
67 stars 23 forks source link

Treeshaking bug: Import module without export #1083

Open SRoeffaers opened 5 years ago

SRoeffaers commented 5 years ago

When I for examle do this: import 'can/es/can-stache-converters'; It doesn't work when I build it with tree shaking enabled. When I disable tree shaking, it does work. I think it can't handle module imports without explicit named imports

justinbmeyer commented 5 years ago

You shouldn’t import this file if you are using tree-shaking. Just import {stashConverters} from “can”

matthewp commented 5 years ago

There's probably still a bug here worth looking into though.

SRoeffaers commented 5 years ago

But I won't be doing anything with 'stashConverters'.. It's just needed in the stache-files. My linter will mark it as an unused variable..

matthewp commented 5 years ago

@Kleppo do this:

import { stache, stacheConverters } from 'can';

stache.addConverter(stacheConverters);
SRoeffaers commented 5 years ago

Ah thx, good idea! :-)

leoj3n commented 5 years ago

I think I've encountered this as well.

My workaround was to, in the context of this example, add to package.json:

"dependencies": {
---snip---
  "can-stache-converters": "*",
---snip---
}

I think this tells steal to include that module, so it doesn't get thrown away during tree shake, but I'm not really sure. The "*" means "any" version, so whatever version of that package included with can. Here are the modules I'm doing this for to avoid the errors that would otherwise appear:

    "can-connect": "*",
    "can-event-dom-enter": "*",
    "can-stache-route-helpers": "*",

Is this actually a solution? Is there a negative to doing this?