Strange error with webpack compilation:
ERROR in Must have a source file to refactor.
Looking at the source code I found this message in ./node_modules/@ngtools/refactor.js:
...   
if (!sourceFile) {
  throw new Error('Must have a source file to refactor.');
}
The configuration of @ngtools webpack plugin is pretty straightforward:
  {
    test: /\.ts$/,
    use: '@ngtools/webpack',
  } 
                Don't forget to include AngularCompilerPlugin with correct mainPath configuration in webpack.config.js. At least that's what fixed this for me.
plugins: [
  /**
   * Angular's webpack plugin to compile typescript and AOT for templates
   **/
  new ngTools.AngularCompilerPlugin({
    tsConfigPath: path.join(CONTEXT_DIR, "tsconfig.json"),
    mainPath: path.join(CONTEXT_DIR, "src/main.ts")
  }),
...
]
                        For anyone in pain, attempting to find this solution; merely change:
new AngularCompilerPlugin({
      mainPath: 'src/main.ts',<----
      tsConfigPath: 'src/tsconfig.app.json',
      skipCodeGeneration: true
    }),
..to this:
new AngularCompilerPlugin({
      mainPath: 'main.ts',<----
      tsConfigPath: 'src/tsconfig.app.json',
      skipCodeGeneration: true
    }),
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With