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

ngDevMode is not defined, when building Angular 15.2 or higher #339

Closed
2 tasks
vzakharov-rxnt opened this issue Sep 13, 2023 · 2 comments
Closed
2 tasks
Labels
bug Something isn't working pending triage

Comments

@vzakharov-rxnt
Copy link

vzakharov-rxnt commented Sep 13, 2023

Problem

After upgrading from prior 15.2 to 15.2 or later (including latest 16.x), I am getting ngDevMode is not defined error on app load. The error is terminating, app does not load.

I am using custom webpack plugin and esbuild-loader to build my app.

I reproduced the issue using standard Angular boilerplate project here:

To prove that it works fine in 15.1, I created a branch where the issue is fixed, and opened a PR to merge. Only package.json was changed, downgrading Angular to 15.1. PR triggers CI build, so you can confirm that the issue is indeed fixed:

Angular team rejected my ticket as unsupported, apparently they don't support custom webpack at all.

Relevant bits of the custom webpack config, if commented out, the build works fine.

const { EsbuildPlugin } = require("esbuild-loader");
//...

if (options.optimization) {
  // https://how-to.dev/how-to-speed-up-angular-cli-app-with-esbuild-loader
  // remove 2 first minimizers, hoping they are the TerserPlugin
  config.optimization.minimizer.shift();
  config.optimization.minimizer.shift();

  config.optimization.minimizer.unshift(
    new EsbuildPlugin(),
  );
}

Expected behavior

If Angular CLI can minify it without build or startup errors, so should the EsbuildPlugin.

Minimal reproduction URL

https://ng-esbuild-minify.netlify.app/

Version

"esbuild-loader": "4.0.2",

Node.js version

v18.17.1

Package manager

npm

Operating system

Windows

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@vzakharov-rxnt vzakharov-rxnt added bug Something isn't working pending triage labels Sep 13, 2023
@JeanMeche
Copy link

JeanMeche commented Sep 13, 2023

You can already do what you want be defining ngDevMode in a similar way the Angular CLI does it :

new EsbuildPlugin({
   define: { ngDevMode: "undefined" },
})

The current CLI implementation for reference : https://github.com/angular/angular-cli/blob/6a97d41b7d8c4cdecaf1b6d57f730a2e5ac326d8/packages/angular_devkit/build_angular/src/tools/esbuild/application-code-bundle.ts#L261

@vzakharov-rxnt
Copy link
Author

It worked! Thank you, @JeanMeche.
I am surprised Angular team rejected the issue with such a simple solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage
Projects
None yet
Development

No branches or pull requests

2 participants