Skip to content

Bad absolute paths in TS auto imports due to new baseUrl #5875

Closed
@cyrilletuzi

Description

@cyrilletuzi
- [X] bug report

Versions.

cli 1.0.0 (since rc.2)
typescript 2.2.2 (which is installed by default by the cli)

Repro steps.

typescript 2.2 introduced quickfixes for auto importing missing classes (in VS Code, a class not imported will be underlined in red, you can click on it, then on the bulb, and it would add the import).

with angular-cli rc.1, it would generate relative imports (the default behavior) :

import { SomeService } from './some.service';

since angular-cli rc.2, as a "baseUrl": "src" has been introduced in the root tsconfig.json, the auto imports are now generated with absolute paths :

import { SomeService } from 'app/feature/some.service';

And, unless I'm wrong, it's bad practice (in particular for refactoring).

@intellix says in #5353 baseUrl was introduced because :

When you're in VSC and write code like: import { environment } from 'environments/environment', it's flagged as being incorrect because the IDE doesn't know about tsconfig.app.json

But the CLI doesn't generate that, it generates this in main.ts :
import { environment } from './environments/environment';

which is the convention and which works perfectly fine, without baseUrl.

So except I'm missing something, this change should be reversed (I can do the PR if it's OK).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions