peaches
peaches

Reputation: 156

Angular 2 Webpack AOT cannot resolve entryModule

I am trying to setup an AOT build using Angular 2 and Webpack (JIT build works fine). Whenever I attempt to build it, I get ERROR in Could not resolve "src/app/app.module" from "src/app/app.module". I have tried removing webpack plugins besides the AotPlugin, used every combination of relative/absolute paths for the AotPlugin options, all to no results. I am using webpack 2.2.1, typescript 2.0.10, @ngtools/webpack 1.2.9 and node version 6.9.4. Any help would be amazing, thanks!

Snippets from webpack.config:

module: {
  rules: [
    { test: /\ts$/, loader: @'ngtools/webpack }
  ]
}

plugins: [
  new webpack.NoEmitOnErrorsPlugin(),
  new AotPlugin({
    tsConfigPath: './tsconfig.json',
    entryModule: 'src/app/app.module#AppModule',
    mainPath: 'src/main'
    }),
  new webpack.optimize.UglifyJsPlugin({
    beautify: false,
    mangle: {
      screw_ie8: true,
      keep_fnames: true
    },
    compress: {
      warnings: false,
      screw_ie8: true
    },
    comments: false
  }),
  new ExtractTextPlugin('[name].[hash].css'),
  new webpack.DefinePlugin({
    'process.env': {
    'ENV': JSON.stringify(ENV)
    }
  })
]

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "src",
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },
  "compileOnSave": false
}

Upvotes: 1

Views: 518

Answers (1)

peaches
peaches

Reputation: 156

Answering my own question, there must have been a path issue. I had been using a helper function for paths and for some reason didn't in this case.

helper function:

var path = require('path');

var _root = path.resolve(__dirname, '..');
function root(args) {
  args = Array.prototype.slice.call(arguments, 0);
  return path.join.apply(path, [_root].concat(args));
}

use:

entryModule: root('src', 'app', 'app.module#AppModule')

Upvotes: 3

Related Questions