ERROR in ./src/uni/server-aot.ts Module not found: Error: Can't resolve '../../aot/src/uni/app.server.ngfactory' in '/Users/techdomain/Documents/universal/src/uni' @ ./src/uni/server-aot.ts 3:0-82 @ multi ./src/uni/app.server.ts ./src/uni/server-aot.ts

If you are using angular universal, and are following the tutorial in angular documentation, then you can get the above issue if you do not make some changes in the config files.

1 . The webpack.config.uni.js file has 3 changes, apart from the two mentioned in the documentation.

The plugins config in the `webpack.config.uni.js` file should be 

    plugins: [
            new ngtools.AotPlugin({
                tsConfigPath: './tsconfig-uni.json'
            }),
            new webpack.optimize.UglifyJsPlugin({ sourceMap: true })
    ],

So instead of ./tsconfig-aot.json, use ./tsconfig-uni.json

2 . Copy the contents of index.html to index.aot.html. It should be something like this

index.aot.html

<!DOCTYPE html>
<html>
  <head>
    <base href="/">
    <title>Angular Tour of Heroes</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="styles.css">

    <!-- Polyfills -->
    <script src="node_modules/core-js/client/shim.min.js"></script>

    <script src="node_modules/zone.js/dist/zone.js"></script>

  </head>

  <body>
    <my-app>Loading...</my-app>
    <script src="dist/build.js"></script>

  </body>

3 . Absolute path in webpack config

If you are getting error like Invalid configuration object.

Webpack has been initialised using a configuration object that does not match the API schema.

  • configuration.output.path: The provided value "./src/dist" is not an absolute path!

Then specify absolute path as the error describes. So instead of ./src/dist, give the absolute path to the file /Users/techdomain/Documents/universal/src/dist