Can VS Code automatically update JavaScript and TypeScript import paths on file rename/move?

前端 未结 2 1097
日久生厌
日久生厌 2021-02-12 18:28

Is there a module for vscode that would update paths towards files? e.g. if I have:

import \'./someDir/somelib\'

and I rename or move so

2条回答
  •  既然无缘
    2021-02-12 19:11

    As @jamey graham mentioned, it stopped working for me in a React typescript project. The fix was to update the tsconfig.json file to have:

    {
      "compilerOptions": {
        "baseUrl": "./src",
        // ...
      },
    }
    

    and to remove the "include": ["src"] option just for moving the files. VS Code should update the paths nicely after this.

    You can bring back the "include": ["src"] option after this.

    I do not know why removing the "include": ["src"] worked though.

    If this doesn't do the trick, try opening a .ts file and trigger the Typescript: Restart TS server option in the command prompt and try again.

提交回复
热议问题