Dheeraj Agrawal
Dheeraj Agrawal

Reputation: 2357

Angular 4 AOT with webpack

I am using angular 4 with webpack 2 & trying to use AOT, but its giving me this error: 10% building modules 4/5 modules 1 active ..._modules/intl/locale-data/jsonp/en.jsModuleNotFoundError: Module not found: Error: Can't resolve './../$$_gendir/src/app/app.module.ngfactory' in '/Users/xyz/angular-upgrade/backend/myapp/angular/src'.

This is my webpack.config:

new AotPlugin({
  tsConfigPath: './tsconfig.json',
  entryModule: './src/app/app.module#AppModule'
}),

and the script I am using to make the build is: "build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail"

Below is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es2015", "dom"],
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true
  },
  "exclude": [
    "node_modules",
    "bower_components"
  ]
}

Upvotes: 4

Views: 6427

Answers (3)

Robert
Robert

Reputation: 1940

First of all: you need to compile using @ngtools/webpack. Then your compiler options are not as Angular would expect them to be.

Please make sure you configure your setup and tsconfig.json according to the Official Angular AOT Cookbook

E.g. the module property needs to be set to:

"module": "es2015"

Also, you should tell ngc where to put generated sources by specifying

"angularCompilerOptions": {
 "genDir": "aot",
 "skipMetadataEmit": true
}

Upvotes: 2

Brandon Culley
Brandon Culley

Reputation: 1334

I had a similar error with $$_gendir

per this post removing --bail from the build command cli enabled me to see more of the error message since $$_gendir errors are more of a generic message caused by prior errors in the build.

Upvotes: 0

Some Guy
Some Guy

Reputation: 31

AOT does not support typescript version that is above 2.0.10 now. You need to make sure that. Also, you have to change some angular modules like http, platform-browser, or core back to angular 2 -- I use version 2.4.0 --, because typescript of version 2.0.10 or below does not support them!

Upvotes: 3

Related Questions