Skip to content

inject migration fails to migrate file at given path #62866

@MikeDabrowski

Description

@MikeDabrowski

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

when executing ng g @angular/core:inject --path \src\app\utils\transloco\custom-transpiler.ts I am receiving the error:

Debug Failure. Expected C:/Users/mike/PingenProjects/pingen2ui/src/app/utils/transloco/custom-transpiler.ts === C:\Users\mike\PingenProjects\pingen2ui\src\app\utils\transloco\custom-transpiler.ts. 

The same error occurs when

  • passing forward slashes /
  • passing backslashes \
  • passing file

I did not try passing only the directory because I don't want to convert other files in it.

I traced its source to typescript itself:

function attachFileToDiagnostic(diagnostic, file) {
  const fileName = file.fileName || "";
  const length2 = file.text.length;
  Debug.assertEqual(diagnostic.fileName, fileName); <-- HERE
  Debug.assertLessThanOrEqual(diagnostic.start, length2);
  Debug.assertLessThanOrEqual(diagnostic.start + diagnostic.length, length2);
  const diagnosticWithLocation = {
    file,
    start: diagnostic.start,
    length: diagnostic.length,
    messageText: diagnostic.messageText,
    category: diagnostic.category,
    code: diagnostic.code,
    reportsUnnecessary: diagnostic.reportsUnnecessary
  };
  if (diagnostic.relatedInformation) {
    diagnosticWithLocation.relatedInformation = [];
    for (const related of diagnostic.relatedInformation) {
      if (isDiagnosticWithDetachedLocation(related) && related.fileName === fileName) {
        Debug.assertLessThanOrEqual(related.start, length2);
        Debug.assertLessThanOrEqual(related.start + related.length, length2);
        diagnosticWithLocation.relatedInformation.push(attachFileToDiagnostic(related, file));
      } else {
        diagnosticWithLocation.relatedInformation.push(related);
      }
    }
  }
  return diagnosticWithLocation;
}
Image Image

As you can see from the path - things are not working on Windows machine.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Debug Failure. Expected C:/Users/mike/PingenProjects/pingen2ui/src/app/utils/transloco/custom-transpiler.ts === C:\Users\mike\PingenProjects\pingen2ui\src\app\utils\transloco\custom-transpiler.ts. 

Please provide the environment you discovered this bug in (run ng version)

Windows 11, ng 20.1.3^

Anything else?

tsconfigPath seems to resolve to the file passed via path, not to the tsconfig

Metadata

Metadata

Assignees

Labels

area: coreIssues related to the framework runtimearea: migrationsIssues related to `ng update`/`ng generate` migrationsstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions