Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR in Must have a source file to refactor

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',
  } 
like image 257
Stepan Suvorov Avatar asked Mar 30 '18 14:03

Stepan Suvorov


Video Answer


2 Answers

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")
  }),
...
]
like image 167
kvetis Avatar answered Oct 05 '22 23:10

kvetis


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
    }),
like image 36
Jason Mullings Avatar answered Oct 05 '22 23:10

Jason Mullings