-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[@nrwl/webpack] Minification does not work correctly (with node
target)
#12782
Comments
This is also an issue for NestJS with TypeORM and generates errors in production such as the one below.
I used a similar workaround to @Lukas-Kullmann's webpack config above with |
Can confirm, I encounter the same issue with build. Seems like somehow changing to webpack build makes it not able to use Map correctly. Also because of the default obfuscation done by webpack, if you use swagger document in NestJS, the schema class names will come out as single letter as name. I used the workaround by @Lukas-Kullmann and works well. |
#12834 I faced the same problem. Also minimal repo is provided there |
We are having this issue to. There is currently NO WAY to turn off optimization for nx/packages/webpack/src/utils/with-nx.ts Line 188 in 2b23963
|
I think this is back on, maybe I'm doing something wrong. I created a nestjs project and I'm using require.resolve and in the dist folder the module is not there. I tried diff solutions, optimization, webpack none worked. could you help? Thank you |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
Firstly, a bit of context where I'm coming from (feel free to skip this paragraph since it is not super important):
I recently upgraded nx from 13.0.1 to 15.0.1. However, after that upgrade, I noticed that
mikro-orm
did not start any more. I got this weird errorPlease provide either 'type' or 'entity' attribute in n.xxx
, which did not occur before. After some digging I noticed that it basically merged all of the metadata for my entities together into one big old definition. And it would throw the error above for entities that did not have the corresponding property (in this casexxx
). After even more digging, I found out that everything worked great with nx 14.7.8 and it broke in 14.7.9. I looked at the changes, debugged into the webpack executor and found out, that the optimization does not work the way it used to any more.Currently, no matter what you set as
optimization
in the@nwrl/webpack:webpack
executor, there will be no optimization applied to the webpack config. This means that it will fall back to the default webpack optimization forproduction
mode
(which is basicallynew TerserPlugin({ terserOptions: { compress: { passes: 2 } } });
, see the webpack source code).However, prior to version 14.7.9, there was a default optimization put in place, but it was more or less removed in PR #12130. In this PR, the optimization will only be applied if
options.optimization === true
(see Line 154 in filepackages/webpack/src/utils/config.ts
).However,
options.optimization
is nevertrue
. It is set to{ scripts: true, styles: true }
innormalizeOptions
(seepackages/webpack/src/executors/webpack/lib/normalize-options.ts
on line 29) which is used bywebpackExecutor
to calculate options (seepackages/webpack/src/executors/webpack/webpack.impl.ts
).Coming back to my problem that I described in the first paragraph, you can see what went wrong here: Prior to nx 14.7.9, the optimization would leave class names as is. Now, it minifies class names. This seems to break
reflect-metadata
which is used bymikro-orm
to infer types of entities.This problem is present in all versions since 14.7.9 to this day (current version is 15.0.1).
Expected Behavior
I would expect, that this behavior does not change all of a sudden and in an undocumented way in a patch release.
Steps to Reproduce
I think this is quite hard to reproduce, but I hope it should be clear from the explanation above
Potential fix and workaround
I think the easiest fix would be to change the condition in packages/webpack/src/utils/config.ts on line 157 to
internalOptions.isScriptOptimizeOn
(just as it is used on line 175 in the same file).In the mean time, a workaround would be to use a custom webpack config (see
webpackConfig
option for the@nrwl/webpack:webpack
executor):Failure Logs
nx does not fail in any way.
Environment
@nrwl/webpack > 14.7.8
The text was updated successfully, but these errors were encountered: