angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

touched/untouched not working with ng build --prod

Open MaxGorshkov opened this issue 8 years ago • 39 comments

Versions

ng --version

Angular CLI: 1.6.2
Node: 9.3.0
OS: win32 x64
Angular: 5.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.2
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.2
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.4.2
webpack: 3.10.0

Repro steps

  • Step 1 ng new testProject
  • Step 2 cd testProject
  • Step 3 npm install
  • Step 4 add code in /src/app/app.component.html:
  <li>
    <h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
  </li>
  <!--my code begin-->
  <li>
    <div>
      <label>field</label>
      <input [(ngModel)]="model.field" #field="ngModel"/>
    </div>
  </li>
  <li>
    <div>untouched - {{field.untouched}} </div>
    <div>pristine - {{field.pristine}} </div>
  </li>
  <!--my code end-->
  • Step 5 add code in /src/app/app.component.ts:
export class AppComponent {
  title = 'app';
  // my code begin
  model = {
    field: ''
  };
  // my code end
}
  • Step 6 add code in /src/app/app.module.ts:

import { FormsModule, ReactiveFormsModule } from '@angular/forms'; ...

  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule
  ],
  • Step 7 npm run build

Observed behavior

wrong

Desired behavior

as after run ng serve: success

MaxGorshkov avatar Dec 26 '17 08:12 MaxGorshkov

@Alekcei, take a look at https://github.com/angular/angular-cli/issues/8997#issuecomment-353970841

julianobrasil avatar Dec 26 '17 21:12 julianobrasil

Sorry. npm i [email protected] --save-exact

[alekcei@localhost BID]$ npm ls uglify-es
[email protected] /home/alekcei/workspase/BID
├─┬ @angular/[email protected]
│ └─┬ [email protected]
│   └── [email protected]  deduped
└── [email protected] 

Yes, it's working now большое спасибо

Alekcei avatar Dec 26 '17 21:12 Alekcei

But not working --no-build-optimizer

ERROR Error: No NgModule metadata found for 'function (){}'.
    at t.TMtu.t.resolve (2.b2a6116….chunk.js:1)
    at t.TMtu.t.getNgModuleMetadata (2.b2a6116….chunk.js:1)
    at e.TMtu.t._loadModules (2.b2a6116….chunk.js:1)
    at e.TMtu.t._compileModuleAndAllComponents (2.b2a6116….chunk.js:1)
    at e.TMtu.t.compileModuleAndAllComponentsAsync (2.b2a6116….chunk.js:1)
    at t.TMtu.t.compileModuleAndAllComponentsAsync (2.b2a6116….chunk.js:1)
    at Function.TMtu.t.createDinamicPetitionOperationComponent (2.b2a6116….chunk.js:1)
    at t.TMtu.t.createOperationsPetitionContent (2.b2a6116….chunk.js:1)
    at e._next (2.b2a6116….chunk.js:1)
    at e.E9/g.e.__tryOrUnsub (vendor.07efdf9….bundle.js:1)
(anonymous) @ vendor.07efdf9….bundle.js:1
LMZF.t.handleError @ vendor.07efdf9….bundle.js:1
next @ vendor.07efdf9….bundle.js:1
e.object.i @ vendor.07efdf9….bundle.js:1
E9/g.e.__tryOrUnsub @ vendor.07efdf9….bundle.js:1
E9/g.e.next @ vendor.07efdf9….bundle.js:1
E9/g.e._next @ vendor.07efdf9….bundle.js:1
E9/g.e.next @ vendor.07efdf9….bundle.js:1
TO51.e.next @ vendor.07efdf9….bundle.js:1
LMZF.e.emit @ vendor.07efdf9….bundle.js:1
(anonymous) @ vendor.07efdf9….bundle.js:1
t.invoke @ polyfills.947cc91….bundle.js:1
r.run @ polyfills.947cc91….bundle.js:1
LMZF.t.runOutsideAngular @ vendor.07efdf9….bundle.js:1
onHandleError @ vendor.07efdf9….bundle.js:1
t.handleError @ polyfills.947cc91….bundle.js:1
r.runTask @ polyfills.947cc91….bundle.js:1
e.invokeTask @ polyfills.947cc91….bundle.js:1
v @ polyfills.947cc91….bundle.js:1
d @ polyfills.947cc91….bundle.js:1

again missing MetaData

Alekcei avatar Dec 26 '17 21:12 Alekcei

Got a weird behavior: focus event on input fired four times on page load (no autofocus, ofc), both ngSubmit and submit events stopped working (page loaded on submit) and many other html event issues. Fixed by removing --prod.

Ledzz avatar Dec 26 '17 22:12 Ledzz

I have similar issue - events from a nested component which are emmitted from ngFor are not handled properly by parent component. Example:

@Component({
  selector: 'cdg-list',
  template: `
                <ul>
                    <li *ngFor="let item of items">
                        <a (click)="addItem.next()">Add</a>
                        <a (click)="deleteItem.next()">Delete</a>
                        <a (click)="editItem.next()">Edit</a>
                    </li>
                </ul>
            `,
})
export class ListComponent {
  @Input() items: any[] = [];

  @Output() addItem = new EventEmitter();
  @Output() deleteItem = new EventEmitter();
  @Output() editItem = new EventEmitter();
}


@Component({
  selector:        'app',
  template:        `
                       <cdg-list [items]="['foobar', 'foo', 'test', 'bar']"
                                 (addItem)="onAdd()"
                                 (editItem)="onEdit()"
                                 (deleteItem)="onDelete()">
                       </cdg-list>
                   `,
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent {
  onAdd() { alert('ADD'); }
  onDelete() { alert('DELETE'); }
  onEdit() { alert('EDIT'); }
}

In app component, onEdit() handler will always be called, no matter which event gets triggered from 'dumb' component(ListComponent). This only happens when building with --prod switch and if I set uglifier mangle=false then the issue is gone. Not sure if this is the same issue, but the source of this issue is definately the same.

One thing to note is that I'm having this issue with angular/cli 1.5+ (tested it with 1.5.0, up to 1.6.2) and angular 5+ (5.0.0, up to 5.2.0-beta) Example

dojchek avatar Dec 26 '17 22:12 dojchek

@Ledzz, @dojchek : are you seeing the bug after aplying @filipesilva's suggested workaround: https://github.com/angular/angular-cli/issues/8997#issuecomment-353970841?

julianobrasil avatar Dec 27 '17 00:12 julianobrasil

No, the bug is gone with that walk-around (can also be done just by setting mangle=false as suggested above).

dojchek avatar Dec 27 '17 00:12 dojchek

Why angular cli not fix stable versions of dependency packages in package.json? I think, that this strategy saved all angular builds in the world in this case)

MaxGorshkov avatar Dec 27 '17 06:12 MaxGorshkov

@MaxGorshkov uglify-es is the sub-dependency of uglify-js-plugin, fixing uglify-js-plugin version will not help with that.

trotyl avatar Dec 27 '17 06:12 trotyl

@julianobrasil didn't try this, I've used this method

Ledzz avatar Dec 27 '17 07:12 Ledzz

The solution from @filipesilva worked for me.

joaopgrassi avatar Dec 27 '17 08:12 joaopgrassi

@MaxGorshkov Angular CLI does not have a direct dependency in uglify-es, like @trotyl said, and so we cannot pin it. Even if we did, [email protected] is not a prerelease version or anything, it is an official stable version.

Pinning (using a specific version of a dependency) does not work because you cannot pin subdependencies. In the NPM ecosystem the way you ensure reproducible installs is not via pinning dependencies but rather by using lockfiles, either package-lock.json or yarn.lock.

filipesilva avatar Dec 27 '17 09:12 filipesilva

@filipesilva => #9006

That moment when serious bouts of insomnia are actually beneficial :)

This has been pinned in uglifyjs-webpack-plugin to [email protected] available in uglifyjs-webpack-plugin@^1.1.5

Prior to the next CLI release, anyone having issues should be able to pin the uglifyjs-webpack-plugin to ^1.1.5 and get a working version of uglify-es

joshwiens avatar Dec 27 '17 10:12 joshwiens

Thanks @d3viant0ne, will try to get a release of Angular CLI up. @danbucholtz you might want to pin as well on Ionic's side.

filipesilva avatar Dec 27 '17 10:12 filipesilva

Keeping issue opened until the workaround is released.

filipesilva avatar Dec 27 '17 12:12 filipesilva

The bug causing these problems is reported with repros at https://github.com/mishoo/UglifyJS2/issues/2663.

filipesilva avatar Dec 27 '17 15:12 filipesilva

@angular/[email protected] is now released, which should set the minimum version of uglifyjs-webpack-plugin to use a pinned [email protected]. Big thanks to @d3viant0ne for updating and releasing it 👍

Meanwhile https://github.com/mishoo/UglifyJS2/issues/2663 has also been fixed and should be part of the next release of uglify-es.

filipesilva avatar Dec 27 '17 21:12 filipesilva

nice work . i can update now.

100cm avatar Dec 28 '17 02:12 100cm

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.