Visual Studio Code: Copying files without breaking import paths
Asked Answered
E

2

6

How can I copy files from one directory to another in Visual Studio Code, without breaking the import paths? In other words, are there any plugins or tools available for readjusting the relative paths in my imports?

Thanks in advance

Elizaelizabet answered 11/6, 2021 at 6:4 Comment(3)
Go to your - file -> preference -> settings -> search for update Imports on file move -> change it to always and reload .Schell
It's always by default on my Visual Studio Code. But when I copy files react complains that it cannot find my filesElizaelizabet
then make a copy in the same directory (filenameX.js), move this file and remove the XAlon
E
2

As @rioV8 pointed out, import paths get automatically rewrittenwork fine if you make a copy of your file in the same directory and move it to the destination folder. If it doesn't work,

Go to your - file -> preference -> settings -> search for update Imports on file move -> change it to always and reload.

Thank you @Shyam and @rioV8

Elizaelizabet answered 11/6, 2021 at 6:44 Comment(0)
K
0

I had the same problem in React + Vite project. Turns out the problem was caused by aliases I had configured in Vite config.

export default defineConfig({
  plugins: [react()],
      alias: [
      { find: "@", replacement: path.resolve(__dirname, "src") },
         
    ],
  },
 
});

So to make it work I had to add jsconfig.json file in project root:

{
    "compilerOptions": {
        "target": "ES6",
        "baseUrl": ".",
        "paths": {
            "@/*": ["src/*"]
      }
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ]
}

With this file vscode is updating moved imports without problem.

Kibitzer answered 21/11, 2022 at 22:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.