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

Angular 6: "Cannot read property 'CLASS_TO_PLAIN' of undefined" when using the buildOptimizer #147

Closed
realmar opened this issue May 6, 2018 · 5 comments
Labels
status: wontfix type: fix Issues describing a broken feature.

Comments

@realmar
Copy link

realmar commented May 6, 2018

Hey all!

I'm using class-transformer in my angular app. I recently upgraded the project to Angular 6 and class-transformer started throwing the following exceptions when transforming from class to plain and from plain to class:

// class to plain
Cannot read property 'CLASS_TO_PLAIN' of undefined

// plain to class
Cannot read property 'PLAIN_TO_CLASS' of undefined

I noticed that those issues only occur when enabling the buildOptimizer: true in angular.json. I would appreciate any help on the matter!

realmar added a commit to realmar/Tamandua-Web that referenced this issue May 7, 2018
…shim for node global object to polyfill (fixes: angular/angular-cli#9827 (comment)) Note: at some point in time those two hacks should be removed
@creativec0de
Copy link

i have the same problem too

@realmar
Copy link
Author

realmar commented May 7, 2018

This is an issue with the angular build-optimizer and has been discussed here. As per this comment, the issue should be fixed. However, it seems like there is a regression in the full release of v6 which causes the enums to be stripped out again:

A workaround is described here

I have forked class-transformer and have fixed the issue there by just using strings for the TransformationType enum: (I also moved this enum to a separate file and removed the duplicate definition of it in index.ts)

export enum TransformationType {
    PLAIN_TO_CLASS = "0",
    CLASS_TO_PLAIN = "1",
    CLASS_TO_CLASS = "2"
}

If you would like I can open a PR with the changes, however I don't know if that would be fitting as the described behavior is a bug in angular and not in class-transformer. You can see the changes I made here.

realmar added a commit to realmar/class-transformer that referenced this issue May 7, 2018
…move duplicate definition and use strings for the enum type. Fixes typestack#147 See also: angular/angular-cli#7613 (comment)
@realmar
Copy link
Author

realmar commented May 11, 2018

This issue has now been fixed in v6.0.1 of the angular devkit (angular/devkit@959826b). Closing this issue.

@realmar realmar closed this as completed May 11, 2018
@NoNameProvided NoNameProvided added type: fix Issues describing a broken feature. status: wontfix labels Oct 26, 2018
@NoNameProvided
Copy link
Member

Thanks for the clear explanation for the future readers.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: wontfix type: fix Issues describing a broken feature.
Development

No branches or pull requests

3 participants