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

ES classes in dependencies aren't transpiled #1505

Open
nlundquist opened this issue Aug 28, 2019 · 7 comments
Open

ES classes in dependencies aren't transpiled #1505

nlundquist opened this issue Aug 28, 2019 · 7 comments

Comments

@nlundquist
Copy link

nlundquist commented Aug 28, 2019

Reproducible: Always

Description:
When using native classes from an NPM dependency (e.g CanJS 6) they're not transpiled even though app modules are transpiled. This is an issue when the app modules include classes that extend the classes from an NPM dependency, e.g:

import ObservableObject from 'can-observable-object';
class Todo extends ObservableObject {
    ...
}
const todo = new Todo();

This will result in an error along the lines of:
Uncaught TypeError: Class constructor Child cannot be invoked without 'new'

This is because the ObservableObject class is not transpiled, but the Todo class is transpiled and transpiled classes cannot extend native classes since transpiled classes try to call their base class like a function rather than invoking with new.

It's unclear what the correct solution to this problem is. Depending on the supported browsers for your app one solution may be to prevent class transpilation inside app modules. The other option would be to apply transpilations to NPM dependencies so all classes are transpiled. Both have downsides. Stopping transpilation limits browser support, increasing transpilation increases bundle size and increases dev mode transpilation delays.

@nlundquist nlundquist changed the title only some ES classes in a project get transpiled ES classes in dependencies aren't transpiled Aug 28, 2019
@matthewp
Copy link
Member

I think the bug here is the way ES classes are transpiled to constructor functions. They are not compatible with ES base classes.

@matthewp
Copy link
Member

Otherwise #1276 is needed.

@justinbmeyer
Copy link
Contributor

Could we just avoid classes in our code?

@matthewp
Copy link
Member

That wouldn't solve this steal issue, no.

@frank-dspeed
Copy link
Contributor

frank-dspeed commented Jul 12, 2020

i have a way to handle that but i need some extra info is Steal's output formart still Systemjs loader compatible or lets say SystemJS compatible when systemjs gets loaded as Steal? @matthewp

@matthewp
Copy link
Member

@frank-dspeed Sorry, I don't understand your question. can you rephrase?

@frank-dspeed
Copy link
Contributor

Conclusion

as maybe some people know i am working on stuff like typescript rollup vscode.

  • Class should not get automaticly transpiled. Or Needs to get Always Transpiled and WebComponents Polyfill loaded

As WebComponents Pollyfill is big and hugh It is more clever to transpil WebComponents into a other Formart like canjs-view-parser :D

The CanJS way is the most efficent and compatible that still exists. It is a WebComponents Pollyfill it self,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants