27

I get this below error after upgrading my angular-cli

ERROR in Template parse errors:
Can't bind to 'index' since it isn't a known property of 'tag'. ("own)="handleKeydown($event, item)"
             (onTagEdited)="onTagEdited.emit(item)"
             [ERROR ->][index]="i"
             [attr.tabindex]="readonly ? -1 : 0"
             [class.readonly]="readonly""): TagInputComponent@16:13

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\xxxx\yyyy\eeeee\eeee\src'
 @ ./src/main.ts 5:0-74
 @ multi ./src/main.ts

This error happens when i run ng build --prod and works fine when i run ng build without any parameters,

Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
  • update `angular-cli` to the last version, https://github.com/angular/angular-cli#updating-angular-cli – Belter Nov 08 '17 at 07:21

7 Answers7

41

When you run the ng build in angular 2, latest angular-cli automatically runs with --aot parameter (ahead of time compilation), so it is trying to optimize your code. You are having a package that is not yet compatible for optimizing. So you need update to your packages. Most probably the packages that has **forRoot()** in your app.module.ts

I recommend to update all packages.

Easy way to update your package is to use ncu npm package as in below, which i got it from How do I correctly upgrade angular 2 (npm) to the latest version?

Install

npm install -g npm-check-updates

Usage

ncu for display

ncu -u for re-writing your package.json

and run npm install to update your packages

If above did not work, you might need to update your code for aot compliance. Refer this url below to make changes in your code. https://medium.com/@isaacplmann/getting-your-angular-2-library-ready-for-aot-90d1347bcad

Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
Palanivelu Samudi
  • 1,125
  • 1
  • 10
  • 13
30

I had the same issue and how I ended up resolving it was: Delete the enhanced-resolve module from node_modules and then run

npm install enhanced-resolve@3.3.0

After that aot builds worked as expected...

user2094257
  • 1,645
  • 4
  • 26
  • 53
28

Use:

ng build --env=prod 

instead of:

ng build --prod
Byron
  • 445
  • 4
  • 6
  • 7
    This will not build optimized distribution package, for more information refer to angular cli documentation here: https://github.com/angular/angular-cli/wiki/build – Samih A Nov 09 '17 at 12:17
13

Faced second part of this issue.

ERROR in ./src/main.ts
Can't resolve './$$_gendir/app/app.module.ngfactory'

Resolved it by updating angular/cli to 1.2.6 for angular 4

  1. Remove node_modules folder
  2. Update "@angular/cli": "1.0.4" to "@angular/cli": "1.2.6" in package.json under devDependencies
  3. Run npm install

Then executing "ng build --prod" successfully generated the production build.

Saravanan Sachi
  • 2,572
  • 5
  • 33
  • 42
  • build successfully, But errors are there after running `index.html` directly, any idea ? – Pardeep Jain Aug 28 '17 at 07:08
  • while running `index.html` got this error in developer console `SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL .....cannot be created in a document with origin 'null' and URL ` – Pardeep Jain Aug 28 '17 at 07:31
  • Worked for me! Might want to also remove your package-lock.json in addition to node modules folder. – Matt Voda Oct 26 '17 at 02:31
2

Same error after upgrading from Angular 6 to 7.1.4. I followed the instructions found here.

The error returned was:

ERROR in ./src/main.server.ts
Module not found: Error: Can't resolve './app/app.server.module.ngfactory'

When trying to pre-render using the command.

ng run [my-project-name]:server

The reason was I enabled the Ivy Render which is not production ready. By removing the lines:

"angularCompilerOptions": {
  "enableIvy": true
} 

From the tsconfig.json file, all was well in the world again.

Jason
  • 2,555
  • 2
  • 16
  • 17
0

Apparently this unhelpful and confusing error message can be caused by using default exports in your typescript consumed by Angular AOT (prerendering). Using export default class will cause this error with any version of Angular and is currently unsupported. You must change to export class.

To view the current status of the issue and see if it ever gets fixed, see https://github.com/angular/angular/issues/11402. As of my writing this, the issue has been open for over two years, but they do claim it will get fixed one day.

pbristow
  • 1,997
  • 4
  • 26
  • 46
0

For me, I haven't declared my newly created component in module.ts. It worked when I declared it. Check if any of your components are not declared in module.ts.

Aathreya
  • 523
  • 4
  • 10