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
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
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
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.
© 2022 - 2024 — McMap. All rights reserved.
update Imports on file move
-> change it toalways
and reload . – SchellfilenameX.js
), move this file and remove theX
– Alon