-
-
Notifications
You must be signed in to change notification settings - Fork 139
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
Webpack + Typegoose and minification breaks functionality #157
Comments
https://typegoose.github.io/typegoose/guides/advanced/reference-other-classes/#common-problems Duplicate of szokodiakos/typegoose#242 (old repository) TL;DR: minification(/webpack optimization of it) is not supported by typegoose (and "name mangling" will break typegoose because it relies on names, which is not used in this case) because webpack is used, i need to mention: #33 TL;DR: typegoose dosnt support being on the client side i will close this because of the "duplicate" on the old repo and running on the client side (and because of the specific optimization webpack does to minify it) |
Thank you for the quick response. Just a final note, if we preserve class names and function names would there be any conflict? |
probably, because of the "optimizations" web pack does (like reordering statements (functions / classes / statements) / everything into one big file) otherwise it should work PS: i never used webpack and minimization of it, so i dont know what it actually does or what would be affected |
Just to chime in. I ran into this just now when building for production with webpack. All the model names got mangled or merged into one (I couldn't tell exactly what was happening, everything looked like it was being saved using the same model). The quick fix that worked for me was to add the following to the webpack config:
As far as I can tell, typegoose works just fine with webpack if you simply disable mangling. |
FYI this is still big problem because of randomness. Maybe it should be added to your official documentation. https://typegoose.github.io/typegoose/docs/guides/known-issues |
a section for webpack was added in ad0b4ff, it will be up at Known-Issues: Webpack (in a few minutes, when deployed) |
Fix: optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
// sourceMap: true,
terserOptions: {
ecma: 8,
keep_classnames: true,
keep_fnames: true,
},
}),
],
}, Referenced from: szokodiakos/typegoose#242 (comment) |
@singhsoldier13 next time please put your code in code blocks, see Mastering Markdown: Quoting Code |
Versions
What is the Problem?
We are using webpack to build and serverless to deploy our application.
Using the minification optimisation on production it seems TypeGoose gets broken with the errors such as:
We also noticed class names are duplicated so uniqueness is not preserved.
This causes some classes to fail because they get the wrong schema.
Code Example
later:
Webpack:
When we also remove for example the quotes around our itemsRef this breaks the application, getting undefined as a ref then when we run the code.
Do you know why it happens?
no
The text was updated successfully, but these errors were encountered: