Moving ts file gets rid of alias imports

I use Angular CLI and have defined aliases in my tsconfig.

{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@config": ["src/app/config"],
"@core/*": ["src/app/core/*"],
"@env": ["src/environments/environment.ts"],
"@shared/*": ["src/app/shared/*"],
"@testUtils/*": ["src/app/tests/testUtils/*"]
},
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}

But when I try to move a file and search for reference, webstorm basically destroys all my alias imports.

Instead of @core/some-module it replaces these imports by app/core/some-module

 

It's pretty annoying... 

 

Please note that when I write code and let Webstorm import missing classes, it imports it correctly using alias @core/something. Why this behavior on refactor?

6 comments
Comment actions Permalink

can't recreate in 2018.1.1 - when I move a file/folder to a different folder of @core root (i.e. from src/app/core/sub to src/app/core/sub1 or src/app/core/dir/other, etc.) paths remain correct, they still use path mappings from tsconfig.json.

Do you have any other tsconfig.*.json files in subfolders? may be, paths are affected by settings in nearest tsconfig.json on moving? Sample project that shows up the issue would be appreciated

0
Comment actions Permalink

I use Webstorm 2018.1 also. We have also tsconfig.app

 

{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "./",
"types": [],
"paths": {
"@config": ["app/config"],
"@core/*": ["app/core/*"],
"@env": ["environments/environment.ts"],
"@shared/*": ["app/shared/*"],
"@testUtils/*": ["app/tests/testUtils/*"]
}
},
"exclude": [
"test.ts",
"setupJest.ts",
"app/tests/**/*",
"**/*.spec.ts",
"**/*.stub.ts",
"**/*.mock.ts"
]
}

 

 

and tsconfig.spec:

{
"extends": "../tsconfig.json",
"compilerOptions": {
"allowJs": true,
"outDir": "../out-tsc/spec",
"module": "commonjs",
"target": "es5",
"baseUrl": "./",
"paths": {
"@config": ["app/config"],
"@core/*": ["app/core/*"],
"@env": ["environments/environment.ts"],
"@shared/*": ["app/shared/*"],
"@testUtils/*": ["app/tests/testUtils/*"]
},
"types": [
"jasmine",
"node"
]
},
"files": [
"test.ts"
],
"exclude": [
"node_modules"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
0
Comment actions Permalink

Can you recreate the issue in a new sample project? Basic project created with angulr-cli, for example? project and steps would be appreciated

0
Comment actions Permalink

I'm having the same issue in IntelliJ Ultimate 2018.3.4. Here is a project that reproduces the problem for me: https://github.com/webmozart/move-repro

  • If I move test2.ts from src/app/core to src/app/core/sub, the reference in test1.ts gets updated correctly to @app/core/sub/test2
  • If I move test1.ts from src/app/core to src/app/core/sub, the reference in test1.ts gets updated incorrectly to ../test2 instead of remaining @app/core/test2
0

Please sign in to leave a comment.