-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Imports outside of the root break on file rename #16399
Comments
Start a new pull request in StackBlitz Codeflow. |
It feel like counter-intuitive |
Hi, let's discuss this bug, when we load some files whose location is outside of the root, we will call export function ensureWatchedFile(
watcher: FSWatcher,
file: string | null,
root: string,
): void {
if (
file &&
// only need to watch if out of root
!file.startsWith(withTrailingSlash(root)) &&
// some rollup plugins use null bytes for private resolved Ids
!file.includes('\0') &&
fs.existsSync(file)
) {
// resolve file to normalized system path
watcher.add(path.resolve(file))
}
} Solution: Add the top directory of the outside file path to chokidar. |
It seems to be related to caching, and using the following configuration options can temporarily solve this problem. export default defineConfig({
server: {
fs: {
cachedChecks: false,
}
}
}); The external file-level listener seems to only trigger the
@HawtinZeng It seems that there is a high cost associated with modifying the monitored path to be the nearest common parent path of the external path and root path. I think that when handling external module paths ( |
Hi, I have tried your method, it didn't work.Maybe a better solution is offer an option array to define where store external files, then we can watch these paths. Or we can add the new file path into watcher while resolved new file path, It's much better. |
It seems this is caused by #15712. I guess it's happening because of inconsistent values here. vite/packages/vite/src/node/server/index.ts Line 479 in 6a127d6
vite/packages/vite/src/node/fsUtils.ts Line 134 in 6a127d6
|
I hope this is related otherwise I'll create a new issue. Vite now breaks when I'm trying to create a new file and import it anywhere. Same for moving files. And it's the same issue with "Failed to resolve import". The last version where this worked correctly is 5.0.13. Anything above(and including) 5.1.7 breaks in this particular way. |
Describe the bug
I rename files frequently. Some of our files are outside of the root. Vite breaks with
[plugin:vite:import-analysis] Failed to resolve import "../packages/calc.js" from "counter.js". Does the file exist?
after renaming a file that's outside of the root folder. I expect it to not throw an error and just reload the page or hot refresh it.Reproduction
https://stackblitz.com/edit/vitejs-vite-ttd4av?file=app%2Fcounter.js
Steps to reproduce
packages/calc.js
tocalc2.js
app/counter.js
The only way I found to fix it is to restart Vite.
System Info
System: OS: macOS 14.3.1 CPU: (8) arm64 Apple M1 Memory: 96.75 MB / 8.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.18.2 - /usr/local/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.12.1 - /opt/homebrew/bin/npm pnpm: 7.15.0 - ~/Library/pnpm/pnpm Browsers: Chrome: 123.0.6312.107 Safari: 17.3.1
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: