TypeScript Version: 3.1.0-dev.20180626
Visual Studio Code Version: 1.26.0-insider
Search Terms: importModuleSpecifier
Code
settings.json
"typescript.preferences.importModuleSpecifier": "non-relative",
foo/bar.ts
export test = 1;
some/path/file.ts
import { test } from 'foo/bar';
Right-click on foo/bar.ts and choose Rename. Name it foo/baz.ts.
Expected behavior:
some/path/file.ts
import { test } from 'foo/baz';
Actual behavior:
some/path/file.ts
import { test } from '../../foo/baz';
(It's not clear to me if this should be a TS issue or VS Code issue, my apologies if I have misplaced this.)
@krryan What's your tsconfig.json? Without some setting such as baseUrl or paths, we can't use a non-relative path because module resolution will fail.
Sorry; I always forget things. We have "baseUrl": "./" in the tsconfig.json. And auto-import and the quick fix both respect the setting and correctly use import { test } from 'foo/baz';.
@krryan I'm still unable to reproduce this error -- note that a test was added in https://github.com/Microsoft/TypeScript/pull/25745/files#diff-1cfe84c83ad55942aed319fcc7b77fcb . Could you try to come up with a complete reproducing example? (And test with typescript@next which is 3.1.0-dev.20180717)
fwiw I started noticing today that even though my setting is "typescript.preferences.importModuleSpecifier": "auto"
my imports are being renamed to longer paths, using values in my tsconfig 'paths' settings, even when the file import is in the same folder.
@neilsoult Could you test with typescript@next and try to come up with a repro? Does it only happen when renaming files, or do import fixes / import completions have the problem too? (Import fix is when you have an error and a light bulb pops up and offers to import it. Completions is when you type 'foo' and the completion list offers to import it.)
It's hard to create a repro right now, but it seems to happen when moving/renaming files/folders, and may possibly be linked to problems ( like, errors because of import paths and the like ). I'll update if I'm able to create a fully reproducible scenario.
As a small update, I think it is related to the option "typescript.updateImportsOnFileMove.enabled".
When either this is set to "always" or "prompt" and I choose yes at the prompt, it goes through my entire codebase and renames relative imports to longer paths.
Experiencing same issue. Here's repro:
โ .gitignore
โ tsconfig.json
โ
โโโโ.vscode
โ settings.json
โ
โโโโsrc
โโโโA
โ a.ts
โ
โโโโB
b.ts
a.ts:
export let a = () => { };
b.ts:
import { a } from "src/A/a";
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"outDir": "dist",
"baseUrl": "."
},
"include": [
"src/**/*"
]
}
settings.json:
{
"typescript.preferences.importModuleSpecifier": "non-relative"
}
Steps:
a.ts to src/B/b.ts is now ./a (should be src/B/a)a.ts back to src/A/b.ts is now ../A/a (should be src/A/a)Here's a repo:
https://github.com/JacksonKearl/ts-rename-bug-demo
TS Version: 3.0.1-insiders.20180723 (VSCode's version)
VSCode Version: 1.26-insiders
@mjbvz Before calling "getEditsForFileRename", vscode should call "configure" setting global preferences. Note that this can't be done per-file since getEditsForFileRename affects multiple files. It looks like currently there is no "configure" that would tell us the importModuleSpecifier preference.
Ok, should we still call configure on the individual file too or is this not necessary?
Not necessary.
Pushed fixed on VS Code side for this