Solvedangular cli Dump compiled factories

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [X] feature request

Versions.

angular-cli 1.0.0
angular 2.4.10

Repro steps.

With the latest bugfix that uncovered AOT errors, I noticed how hard it is to pinpoint those errors. The reason is that all we get is an error during compilation like this:

ERROR in /src/$$_gendir/app/lazy/support/support.component.ngfactory.ts (2126,52): Supplied parameters do not match any signature of call target.

The offending file is transient and cannot be inspected. Due to the recently fixed bug, the code error has been there for a long time and it is now very difficult to spot the offending code in a module that has been working for months.

Desired functionality.

There should be a way to inspect (= keep) the transient file to get a better idea what the AOT compiler complains about.

15 Answers

✔️Accepted Answer

as work around, I am adding

fs.writeFile(`build-error-${line}-${path.basename(fileName)}`,
  `${fileName} (${line + 1},${character + 1}): ${message}
                ${sourceText}`, (err) => {console.log(err)});

in `node_modules/@ngtools/webpack/src/plugins.js

here:

        if (diagnostics.length > 0) {
            const message = diagnostics
                .map(diagnostic => {
                const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
                const sourceText = diagnostic.file.getFullText();
                let { line, character, fileName } = this._translateSourceMap(sourceText, diagnostic.file.fileName, position);
                const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
fs.writeFile(`build-error-${line}-${path.basename(fileName)}`,`${fileName} (${line + 1},${character + 1}): ${message}
                ${sourceText}`, (err) => {console.log(err)});
                return `${fileName} (${line + 1},${character + 1}): ${message}`;
            })
                .join('\n');
            this._compilation.errors.push(message);
        }

Other Answers:

@valorkin Thanks for showing us that! I ended up modifying your code so that the file name generated has the same line number and character position as the error. I also didn't add the additional error message to the top of the file as that throws off the line number count and instead just put the error message on the same line.

Here's that code incase someone finds it useful.

if (diagnostics.length > 0) {
    const message = diagnostics
        .map(diagnostic => {
        const position = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
        let sourceText = diagnostic.file.getFullText();
        let { line, character, fileName } = this._translateSourceMap(sourceText, diagnostic.file.fileName, position);
        const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
        let lines = sourceText.split("\n");
        lines[line] = lines[line] + `\/\/ERROR: ${message}`;
        sourceText = lines.join("\n");
         fs.writeFile(`build-error-${line + 1}-${character + 1}-${path.basename(fileName)}`,
            `${sourceText}`, (err) => {console.log(err)});
        return `${fileName} (${line + 1},${character + 1}): ${message}`;
    })
        .join('\n');
    this._compilation.errors.push(message);
}

And the comment it makes to the file

  this.context.ngOnChanges(this._changes);//ERROR: Supplied parameters do not match any signature of call target.

I did not find 4.2x to give clearer messages. The error was cause for me by the output event on the component html (myEvent)="myEvent($event)" called a method in the component typescript: myEvent(). Changing it to be: (myEvent)="myEvent()" solved this issue.

Could a flag be added for that (i.e. ng build --keep-gendir)?

More Issues: