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

AOT Giving Generic Error Message when Component is declared in multiple modules

Open deebloo opened this issue 8 years ago • 8 comments

When serving a generated app with AOT enabled some errors are obfuscated behind a misleading error message at build time. This issue is specifically for the same declaration in multiple modules but I believe it happens for others as well but this is the one I have an example for.

Versions

Angular: 5.1.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.0
@angular-devkit/build-optimizer: 0.0.35
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.41
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.0
@schematics/angular: 0.1.10
@schematics/schematics: 0.0.10
typescript: 2.4.2
webpack: 3.10.0

Repro steps

  • clone repo
  • run npm start (command updated with --aot)
  • see error message

Observed behavior

non specific error message shown in terminal:

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './app/app.module.ngfactory' in '/Users/dannyblue/Documents/projects/error-example/src'
resolve './app/app.module.ngfactory' in '/Users/dannyblue/Documents/projects/error-example/src'
  using description file: /Users/dannyblue/Documents/projects/error-example/package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /Users/dannyblue/Documents/projects/error-example/package.json (relative path: ./src)
    using description file: /Users/dannyblue/Documents/projects/error-example/package.json (relative path: ./src/app/app.module.ngfactory)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /Users/dannyblue/Documents/projects/error-example/src/app/app.module.ngfactory doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /Users/dannyblue/Documents/projects/error-example/src/app/app.module.ngfactory.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /Users/dannyblue/Documents/projects/error-example/src/app/app.module.ngfactory.js doesn't exist
      as directory
        /Users/dannyblue/Documents/projects/error-example/src/app/app.module.ngfactory doesn't exist
[/Users/dannyblue/Documents/projects/error-example/src/app/app.module.ngfactory]
[/Users/dannyblue/Documents/projects/error-example/src/app/app.module.ngfactory.ts]
[/Users/dannyblue/Documents/projects/error-example/src/app/app.module.ngfactory.js]
[/Users/dannyblue/Documents/projects/error-example/src/app/app.module.ngfactory]
 @ ./src/main.ts 3:0-66
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

Desired behavior

Terminal should display the correct error message. In the example above the expected error message is. (This is what is shown in JIT mode)

Uncaught Error: Type ExampleComponent is part of the declarations of 2 modules: ExampleModule and AppModule! Please consider moving ExampleComponent to a higher module that imports ExampleModule and AppModule. You can also create a new NgModule that exports and includes ExampleComponent then import that NgModule in ExampleModule and AppModule.

deebloo avatar Dec 13 '17 12:12 deebloo

this may be an angular core issue and not a cli issue as referenced. here https://github.com/angular/angular/issues/20292 and https://github.com/angular/angular-cli/issues/8036#issuecomment-351634002

deebloo avatar Dec 14 '17 13:12 deebloo

@deebloo , have you tried Angular v5.1.1 ? Similar issue was fixed in v5.1.1

Sky4CE avatar Dec 14 '17 13:12 Sky4CE

@PascalPrecht this looks a lot like what we were talking about yesterday. Maybe this is the real issue you are getting?

filipesilva avatar Dec 14 '17 13:12 filipesilva

@Sky4CE I have not. will try now

deebloo avatar Dec 14 '17 13:12 deebloo

@Sky4CE @filipesilva updating to 5.1.1 fixed it. I am now seeing the correct error message

deebloo avatar Dec 14 '17 13:12 deebloo

https://github.com/angular/angular/commit/6727336 seems to be the commit that fixes it.

filipesilva avatar Dec 14 '17 13:12 filipesilva

I am facing this same issue .module.ngfactory.ts doesn't exist .js Field 'browser' doesn't contain a valid alias configuration and seen these comments,

it seems like this line in packate.json "@angular/compiler-cli": "^5.0.0", need to be updated as "@angular/compiler-cli": "^5.1.1",

and install it.

Please confirm.

thanks, Shobhit

shoagraw avatar Feb 15 '18 22:02 shoagraw

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.