Search code examples
reactjstypescriptvisual-studio-codevite

TypeScript › Update Imports On File Move: Enabled not working in VS Code


I've been encountering an issue with Visual Studio Code where the 'TypeScript › Update Imports On File Move: Enabled' setting seems to no longer work as expected.

Previously, I could move a file and the import path would automatically update. However, now it doesn't update despite having the setting configured to 'prompt'. Instead, I have to manually update the file path. After doing so, the filepath is underlined in red and I get the following error:

Cannot find module '@example-path-1' or its corresponding type declarations.ts(2307)

To fix this, I have to restart the TypeScript server for the path to be recognised correctly.

Here's what I've checked so far:

  • The settings in both my user and workspace settings don't conflict.
  • Changing the settings from 'prompt' to 'always'.
  • Restarted Visual Studio Code.
  • Restarted TypeScript server.
  • Cleared TypeScript cache.

I am using Vite, TypeScript, and React. I manage absolute paths using tsconfigPaths in my 'vite.config.ts'. The paths are set up in my 'tsconfig.json' using ./src as the baseUrl:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@example-path-1/*": ["./features/example-path-1/*"],
      "@example-path-2/*": ["./features/example-path-2/*"]
    }
  ...// rest
  }
}

Everything was working fine until recently and I'm unsure why it has suddenly stopped functioning as expected.

Any suggestions or insights on how to resolve this would be greatly appreciated!

Thanks in advance


Solution

  • After further investigation, this turned out to be a bug in the April 2024 (version 1.89) and May 2024 (version 1.90) releases of Visual Code. Moving files with relative paths works fine, but moving files with absolute paths doesn't update the imports correctly.

    Rolling back to the March 2024 (version 1.88) version of Visual Studio Code resolved the issue for me.