angular-cli: ng build --prod --aot not working

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.0
node: 7.2.1
os: linux x64
@angular/common: 4.0.1
@angular/compiler: 4.0.1
@angular/core: 4.0.1
@angular/forms: 4.0.1
@angular/http: 4.0.1
@angular/platform-browser: 4.0.1
@angular/platform-browser-dynamic: 4.0.1
@angular/router: 4.0.1
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.1

Repro steps.

npm install --save-dev @types/googlemaps

and then, change the tsconfig.app.json to:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": ["google.maps", "io"]
  },
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ],
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

if we did not change this file, ng serve fails to provide the google type: Cannot find namespace 'google'. Without this change, the ng build --prod --aot works.

The log given by the failure.

$ ng build --aot --prod

Hash: 0e5ac752f36ed80df3cd                                                              
Time: 3144ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 158 kB {4} [initial] [rendered]
chunk    {1} styles.bundle.js, styles.bundle.js.map (styles) 9.77 kB {4} [initial] [rendered]
chunk    {2} main.bundle.js, main.bundle.js.map (main) 1.09 kB {3} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 806 kB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

ERROR in ./src/main.ts
Module not found: Error: Can't res

Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/luishmcmoreno/tmp/teste/src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 9
  • Comments: 30 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Small Update

I’m still not understanding where is the problem but when I run

$ ng build -prod -aot false

it works and the size of the generated code is about 70% smaller than the normal one

Closing as @luishmcmoreno seems to have his problem sorted. Thanks to everyone that helped out!

Yep same here, just upgraded from angular 2 to angular 4 everything works except when I use the --aot command I get this:

ERROR in Child compilation failed:

Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/home/insta/angularfire/AF4/node_modules/typescript/lib/typescript.js:9514:20)
    at Object.createCompilerHost (/home/insta/angularfire/AF4/node_modules/typescript/lib/typescript.js:63770:26)
    at Object.ngcLoader (/home/insta/angularfire/AF4/node_modules/@ngtools/webpack/src/loader.js:380:33):
TypeError: Cannot read property 'newLine' of undefined

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/home/insta/angularfire/AF4/src'
 @ ./src/main.ts 5:0-74
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
webpack: Failed to compile.

Juste remove "types": entry from tsconfig.

Why angular-cli set "types": [] ?

@Hosar upgrade to 1.3.1 the latest and it should work fine.

This seems to be happening outside of the CLI as well, with @ngtools/webpack in general.