Angular-cli: I can't build AOT and the error is giving me nothing?

Created on 8 Mar 2017  路  21Comments  路  Source: angular/angular-cli

$ ng build -prod --aot

Hash: d230164e916b758d0692
Time: 18475ms
chunk {0} polyfills.c55f89f35c48bf2c6e88.bundle.js (polyfills) 153 kB {5} [initial] [rendered]
chunk {1} scripts.4df4da6c643df8224363.bundle.js (scripts) 750 kB {5} [initial] [rendered]
chunk {2} styles.bd44f3c52773890a1208.bundle.css (styles) 281 bytes {5} [initial] [rendered]
chunk {3} main.daff98269318dace91c3.bundle.js (main) 668 bytes {4} [initial] [rendered]
chunk {4} vendor.094b768043954986be41.bundle.js (vendor) 834 kB [initial] [rendered]
chunk {5} inline.4a76813170987b826954.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in Maximum call stack size exceeded

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/baypublishing/projects/vvink/src'
@ ./src/main.ts 4:0-74
@ multi ./src/main.ts

@angular/cli: 1.0.0-rc.1
node: 6.9.2
os: darwin x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-rc.1
@angular/compiler-cli: 2.4.9

I even created a new project and copied over but no joy?

high 1 (urgent) confusing bufix

Most helpful comment

In my case I solved by removing --bail option from webpack, so that the error actually shows during build!

All 21 comments

Hi @borntodesign ,

This seemed to have been a problem last month due to users not deleting all of their @angular-cli references. Could you please ensure you run:

npm uninstall -g @angular-cli
rm -rf node_modules
npm install

Within your app folder, also what version of ts are you using?

Hi @RicardoVaranda ,

I Still see this error which doesn't say much.
Uninstalled @angular-cli local and global.
Received the error with both TS 2.2.1 and 2.0.10
The only thing that seems to makes it work is removing my nested lazy loaded module.

image

Hi all,

I'm having the same issue

ERROR in Cannot read property 'text' of undefined

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/florinbardosi/Project/src'
@ ./src/main.ts 4:0-74
@ multi ./src/main.ts

@angular/cli: 1.0.0-rc.2
node: 6.9.5
os: darwin x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-rc.2
@angular/compiler-cli: 2.4.9
@angular/language-service: 2.4.8

@RicardoVaranda I actually have since copied it into a completely fresh angular-cli project and still no joy?

In my case I have just

Error
    at factoryCallback (/Users/alex/Sites/project-api/frontend/node_modules/webpack/lib/Compilation.js:259:39)
    at /Users/alex/Sites/project-api/frontend/node_modules/webpack/lib/NormalModuleFactory.js:234:19
    at onDoneResolving (/Users/alex/Sites/project-api/frontend/node_modules/webpack/lib/NormalModuleFactory.js:59:20)
    at /Users/alex/Sites/project-api/frontend/node_modules/webpack/lib/NormalModuleFactory.js:126:20
    at /Users/alex/Sites/project-api/frontend/node_modules/webpack/node_modules/async/dist/async.js:3694:9
    at /Users/alex/Sites/project-api/frontend/node_modules/webpack/node_modules/async/dist/async.js:356:16
    at iteratorCallback (/Users/alex/Sites/project-api/frontend/node_modules/webpack/node_modules/async/dist/async.js:934:13)
    at /Users/alex/Sites/project-api/frontend/node_modules/webpack/node_modules/async/dist/async.js:840:16
    at /Users/alex/Sites/project-api/frontend/node_modules/webpack/node_modules/async/dist/async.js:3691:13
    at apply (/Users/alex/Sites/project-api/frontend/node_modules/webpack/node_modules/async/dist/async.js:21:25)
    at /Users/alex/Sites/project-api/frontend/node_modules/webpack/node_modules/async/dist/async.js:56:12
    at /Users/alex/Sites/project-api/frontend/node_modules/webpack/lib/NormalModuleFactory.js:121:22
    at onResolved (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/Resolver.js:70:11)
    at loggingCallbackWrapper (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at afterInnerCallback (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/Resolver.js:138:10)
    at loggingCallbackWrapper (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (/Users/alex/Sites/project-api/frontend/node_modules/tapable/lib/Tapable.js:181:46)
    at innerCallback (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/Resolver.js:125:19)
    at loggingCallbackWrapper (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at /Users/alex/Sites/project-api/frontend/node_modules/tapable/lib/Tapable.js:283:15
    at /Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:38:4
    at loggingCallbackWrapper (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at afterInnerCallback (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/Resolver.js:138:10)
    at loggingCallbackWrapper (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (/Users/alex/Sites/project-api/frontend/node_modules/tapable/lib/Tapable.js:181:46)
    at innerCallback (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/Resolver.js:125:19)
    at loggingCallbackWrapper (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at /Users/alex/Sites/project-api/frontend/node_modules/tapable/lib/Tapable.js:283:15
    at innerCallback (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/Resolver.js:123:11)
    at loggingCallbackWrapper (/Users/alex/Sites/project-api/frontend/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
resolve './../$$_gendir/src/app/app.module.ngfactory' in '/Users/alex/Sites/project-api/frontend/src'
  using description file: /Users/alex/Sites/project-api/frontend/package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /Users/alex/Sites/project-api/frontend/package.json (relative path: ./src)
    using description file: /Users/alex/Sites/project-api/frontend/package.json (relative path: ./$$_gendir/src/app/app.module.ngfactory)
      as directory
        /Users/alex/Sites/project-api/frontend/$$_gendir/src/app/app.module.ngfactory doesn't exist
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /Users/alex/Sites/project-api/frontend/$$_gendir/src/app/app.module.ngfactory doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /Users/alex/Sites/project-api/frontend/$$_gendir/src/app/app.module.ngfactory.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /Users/alex/Sites/project-api/frontend/$$_gendir/src/app/app.module.ngfactory.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        /Users/alex/Sites/project-api/frontend/$$_gendir/src/app/app.module.ngfactory.json doesn't exist
      .css
        Field 'browser' doesn't contain a valid alias configuration
        /Users/alex/Sites/project-api/frontend/$$_gendir/src/app/app.module.ngfactory.css doesn't exist
      .scss
        Field 'browser' doesn't contain a valid alias configuration
        /Users/alex/Sites/project-api/frontend/$$_gendir/src/app/app.module.ngfactory.scss doesn't exist
      .html
        Field 'browser' doesn't contain a valid alias configuration
        /Users/alex/Sites/project-api/frontend/$$_gendir/src/app/app.module.ngfactory.html doesn't exist

with no explanation on what the problem is

Just upgraded to @angular/cli: 1.0.0-rc.2
In a fresh ng new project, ng build -prod builds fine.

My project builds and runs fine with:

  • ng serve
  • ng build --environment prod --output-hashing=all

However, these break:

  • ng build -prod
  • ng build --environment prod --output-hashing=all --target=production

I'm not sure exactly what _-prod_ or _--target=production_ trigger (AOT?) but the build results in this error:

ERROR in Error encountered resolving symbol values statically. Expression form not supported (position 15:13 in the original .ts file), resolving symbol SearchInputComponent in /home/whitea/Code/boost_dashboard/src/app/shared/search-input/search-input.component.ts

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/whitea/Code/boost_dashboard/src'
@ ./src/main.ts 4:0-74
@ multi ./src/main.ts

SearchInputComponent is the first declared and exported Component in a shared module.
main > AppModule > CoreModule > CoreSharedModule > SearchInputComponent
CoreSharedModule is where I put Components needed by AppComponent in addition to other modules.

Why everyone here has at least an error and I don't have anyhting? :D

In my case I solved by removing --bail option from webpack, so that the error actually shows during build!

I had a dummy file from a previous implementation where we used ngrx. After I've removed the file it's working again.

If you can provide a simple repro we can investigate.

Today, I was able to build fine with ng build -prod --aot on a new project with the v1.0.0 of the cli.

However, I do get the error with the latest version of the AotPlugin and on a basic app:

"@ngtools/webpack": "^1.3.0" - error
"@ngtools/webpack": "^1.2.8" - no error

Module not found: Error: Can't resolve '../aot/app/app.module.ngfactory'

I don't know in which version it started to break.

So I think there's probably a few different bugs going on in this issue, but I have a repro for the error that @florinbardosi originally got in a repo at https://github.com/ycros/angular-aot-cryptic-error-repro - in my case it's including a dependency that I guess is incompatible with AOT in some way, and the actual bug is that the error needs to be clearer.

Regarding the AotPlugin, in #5329 the fix/workaround by proposed by @tinchou worked for me. It is a window-specific problem.

I've also got a missleading "Can't resolve './$$_gendir/app/app.module.ngfactory'" - Error Message when building AOT.

The reason was that I've accidentally deleted one of our sourcefiles called "_spinner.service"_ and I've referenced this file in one of our components and passing it to the constructor by injection

import { SpinnerService } from './spinner.service';
(...)

@Component({
    (...)
})
export class Spinner implements OnInit {
    @Input() isLoading: boolean;

    constructor(private spinnerService: SpinnerService) { }

    (...)
}

which of course gives an error.

Compiling JIT gives the correct error, compiling AOT the missleading "ngFactory" error...

When compiling AOT I get the following missleading error (_"XXX" is the path to our "(...)/src/app" - folder_)

ModuleNotFoundError: Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'XXX\src'
    at factoryCallback (XXX\node_modules\webpack\lib\Compilation.js:264:39)
    at factory (XXX\node_modules\webpack\lib\NormalModuleFactory.js:247:20)
    at resolver (XXX\node_modules\webpack\lib\NormalModuleFactory.js:65:21)
    at asyncLib.parallel.e (XXX\node_modules\webpack\lib\NormalModuleFactory.js:138:21)
    at XXX\node_modules\async\dist\async.js:3838:9
    at XXX\node_modules\async\dist\async.js:421:16
    at iteratorCallback (XXX\node_modules\async\dist\async.js:996:13)
    at XXX\node_modules\async\dist\async.js:906:16
    at XXX\node_modules\async\dist\async.js:3835:13
    at resolvers.normal.resolve (XXX\node_modules\webpack\lib\NormalModuleFactory.js:130:23)
    at onResolved (XXX\node_modules\enhanced-resolve\lib\Resolver.js:70:11)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at afterInnerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:138:10)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (XXX\node_modules\tapable\lib\Tapable.js:181:46)
    at innerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:125:19)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at XXX\node_modules\tapable\lib\Tapable.js:283:15
    at XXX\node_modules\enhanced-resolve\lib\UnsafeCachePlugin.js:38:4
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at afterInnerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:138:10)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (XXX\node_modules\tapable\lib\Tapable.js:181:46)
    at innerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:125:19)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at XXX\node_modules\tapable\lib\Tapable.js:283:15
    at innerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:123:11)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at XXX\node_modules\tapable\lib\Tapable.js:283:15
    at resolver.doResolve.createInnerCallback (XXX\node_modules\enhanced-resolve\lib\DescriptionFilePlugin.js:44:6)
resolve './$$_gendir/app/app.module.ngfactory' in 'XXX\src'
  using description file: XXX\package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: XXX\package.json (relative path: ./src)
    using description file: XXX\package.json (relative path: ./src/$$_gendir/app/app.module.ngfactory)
      as directory
        XXX\src\$$_gendir\app\app.module.ngfactory doesn't exist
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\$$_gendir\app\app.module.ngfactory doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\$$_gendir\app\app.module.ngfactory.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\$$_gendir\app\app.module.ngfactory.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\$$_gendir\app\app.module.ngfactory.json doesn't exist
      .less
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\$$_gendir\app\app.module.ngfactory.less doesn't exist
      .scss
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\$$_gendir\app\app.module.ngfactory.scss doesn't exist
      .css
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\$$_gendir\app\app.module.ngfactory.css doesn't exist
      .html
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\$$_gendir\app\app.module.ngfactory.html doesn't exist
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.

When compiling JIT, I get the correct error message:

ModuleNotFoundError: Module not found: Error: Can't resolve './shared/spinner.service' in 'XXX'
    at factoryCallback (XXX\node_modules\webpack\lib\Compilation.js:264:39)
    at factory (XXX\node_modules\webpack\lib\NormalModuleFactory.js:247:20)
    at resolver (XXX\node_modules\webpack\lib\NormalModuleFactory.js:65:21)
    at asyncLib.parallel.e (XXX\node_modules\webpack\lib\NormalModuleFactory.js:138:21)
    at XXX\node_modules\async\dist\async.js:3838:9
    at XXX\node_modules\async\dist\async.js:421:16
    at iteratorCallback (XXX\node_modules\async\dist\async.js:996:13)
    at XXX\node_modules\async\dist\async.js:906:16
    at XXX\node_modules\async\dist\async.js:3835:13
    at resolvers.normal.resolve (XXX\node_modules\webpack\lib\NormalModuleFactory.js:130:23)
    at onResolved (XXX\node_modules\enhanced-resolve\lib\Resolver.js:70:11)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at afterInnerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:138:10)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (XXX\node_modules\tapable\lib\Tapable.js:181:46)
    at innerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:125:19)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at XXX\node_modules\tapable\lib\Tapable.js:283:15
    at XXX\node_modules\enhanced-resolve\lib\UnsafeCachePlugin.js:38:4
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at afterInnerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:138:10)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (XXX\node_modules\tapable\lib\Tapable.js:181:46)
    at innerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:125:19)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at XXX\node_modules\tapable\lib\Tapable.js:283:15
    at innerCallback (XXX\node_modules\enhanced-resolve\lib\Resolver.js:123:11)
    at loggingCallbackWrapper (XXX\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19)
    at XXX\node_modules\tapable\lib\Tapable.js:283:15
    at resolver.doResolve.createInnerCallback (XXX\node_modules\enhanced-resolve\lib\DescriptionFilePlugin.js:44:6)
resolve './shared/spinner.service' in 'XXX\src\app'
  using description file: XXX\package.json (relative path: ./src/app)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: XXX\package.json (relative path: ./src/app)
    using description file: XXX\package.json (relative path: ./src/app/shared/spinner.service)
      as directory
        XXX\src\app\shared\spinner.service doesn't exist
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\app\shared\spinner.service doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\app\shared\spinner.service.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\app\shared\spinner.service.js doesn't exist
      .json
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\app\shared\spinner.service.json doesn't exist
      .less
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\app\shared\spinner.service.less doesn't exist
      .scss
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\app\shared\spinner.service.scss doesn't exist
      .css
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\app\shared\spinner.service.css doesn't exist
      .html
        Field 'browser' doesn't contain a valid alias configuration
        XXX\src\app\shared\spinner.service.html doesn't exist
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.

@alex88 , thanks for the tip. Removing the --bail shows me the real errors.

@hansl it seems the really problematic issue here is how AOT reports an inscrutable error while non-AOT reports something that is actionable (see @Btruckses comment). Can you take a look at why this happens?

+1
Works with --aot=false

Hey @hansl is there another ticket where this is being more actively investigated or is this on hold? AOT reporting with the ngfactory can be quite difficult to decipher.

Can you reproduce this issue with the latest CLI? If this is still valid, would you provide a minimal demo where we can reproduce the problem?

Closing the issue due to inactivity. If the problem still exists in the latest version of the CLI, please open a new issue following the template and providing a minimal demo where we can reproduce it. Thanks! :-)

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._

Was this page helpful?
0 / 5 - 0 ratings