-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: unexpected temporary file #13269
Conversation
Run & review this pull request in StackBlitz Codeflow. |
packages/vite/src/node/config.ts
Outdated
// check and clear legacy Tmp files | ||
const fileBaseName = path.basename(fileName) | ||
const fileDir = path.dirname(fileName) | ||
const timestampFiles = (await fsp.readdir(fileDir)).filter(name=>name.includes(`${fileBaseName}.timestamp-`)) | ||
timestampFiles.forEach(name=>{ | ||
fs.unlink(path.resolve(fileDir,name), () => { }); | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two vite processes may be executed using different cache dirs on the same folder at the same time so this may delete a file while it is being used. Maybe we should move the generation of the file to be in ${cacheDir}/temp/${fileNameTmp}
so we don't need the clean-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea. I'll try to make some modifications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tried to move the file generation to the ${cacheDir} directory, I found that the value of cacheDir could not be obtained in the loadConfigFromBundledFile method. Therefore, I considered whether it was possible to import directly in base64 format without using a temporary file
I think this could work better! I don't see limits affecting using base64 to import the file. Let's queue this for Vite 4.4 just to be on the safe side, and also to give others the opportunity to review the new approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually pretty smart. Looking forward to testing this out.
are there any downsides to this like extra memory overhead for the b64 string or super strange errors that reference it instead of the config file? |
That's a good point @dominikg This is how errors look right now in main:
This is the same error after this PR:
So if we want to do the change, we'll need to catch the error and rewrite it. Would that still be ok? |
As long as we have the |
The |
I think we can definitely improve those, though editing error stacktraces is always a bit risky. But maybe we can improve that later and get this in first since it helps to remove the temporary file (which I've seen from time-to-time) |
I tried this method in an earlier attempt to fix this temp file issue, but ran into the problem of relative import specifiers not working because when node loads a file from a
So I think this method is affected as well. Not that I'd use relative imports in a vite config, but some people surely do. I think VM modules would be the proper solution. |
I also tried using VM to solve it, but I don't know what to do. |
@silverwind if you can reproduce the issue you mentioned, would you share a reproduction that isn't working with this PR so we have it as a reference here? |
If it's true that you rewrite relative paths already and you have test cases confirming relative paths work in both static and dynamic I don't have anything to share, it was just local experimenation that I never commited anywhere. |
@patak-dev I don't know how to rewrite the errorstack in order to get line/column and ensure security...... I may be make modification like this: |
@s10y10 I think we don't need to support line/column for now. What you propose sounds good 👍🏼 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error looks good now. I think we could try during the 4.4 beta. @bluwy, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's give this a go!
With this now reverted do we have any other plans to address the temporary file issue? This completely prevents the ability to use vite on limited filesystems |
@OllysCoding you can workaround it by using a |
if y'all are still having issues just recode the entire thing...painful but it normally starts whenever you start a project and is hard to miss, idk why it happened but it's not a common bug |
Description
Fixes #13267
Fixes #9470
Check and clean temporary files every time loadConfigFromBundledFile is executed.
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).Submitted with StackBlitz Codeflow.