-
-
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
avoid writing the temporary file when evaluating the config file #9470
Comments
vite build
should not write a files outside of "build.outDir"
vite build
should not write a files outside of "build.outDir"vite build
should not write a files outside of build.outDir
It doesn't generate to |
But why does Vite create this file for the ESM config? Look at my
And look at the temporary
There are no significant differences. Maybe Vite should only create the temporary file when needed? |
vite build
should not write a files outside of build.outDir
vite build
should not write a files outside of explicitly set directories (build.outDir
, etc.)
I got the se problem. I'm trying to put vite project into Google app engine which also doesn't allow write. It's throwing me error because vite try to generate the timestamped temp file. |
I'm also having this problem deploying in a Aws Lambda |
I solved it by just using a python yaml instead of a nodejs yaml, as mine is a static website. |
These
Can this file be removed or at least be moved to vite's temp dir |
Files This file needs to be removed somewhere from the parent directory
|
I get this file randomly and need to remove it by hand, quite annoying 😅 |
This is happening to me too. I just threw this in my .gitignore:
|
I took a look a the hack, but it has no easy solution at least. The file must be at the same location for path resolution to work, which is the reason for the file's location. The function already has access to the transpiled source which in theory could be ran as a string without temp files, but node offers no suitable API. VM modules would be suitable but are behind a experimental flag since a long time now. I think the hack solely exists to support Typescript config files, all other variations seem to work fine with node's ESM importer, so the comment above it seems to have become inaccurate over time. |
I think Vite should at least be able to write files to its configured |
#13269 does not fully solve it imho. One solution might be to check With that, people have at least an option to solve this issue of that temp file. It would require the config file to be ESM, but I think that is a given already. Edit: seeing the code of #13269, If that base64 import works, it will actually solve it. |
Can someone link me to a fix? This has taken me down. Hours in and I need to just prune away this vite.config.ts.timestamp-1686938782284-10d99850f42b.mjs but no matter what command, pnpm, npm yarn or shell bash vsh it only wants to run this file, even though it doesn't seem to appear anywhere, it's not hidden either. It's just stuck on only wanting to run this somehow altered config. |
This is actually a really challenging issue to solve because the "bundled" config has to be evaluated in the same directory as the original file itself. I dug into it a bit further and it doesn't look like there is really any solution today without using experimental node features. @patak-dev it would've/could've been worth leaving the base64 encoded data url import in as an option via environment variable flag or something. There's quite a lot of users (myself included) that want to use vite where the source structure is "read only". Though I understand this may just create more headache for the vite team as there will invariably be plugins that break using that env flag and then resulting in issues. |
How do other projects that support |
@silverwind what sort of hacks do you mean? |
By hack I mean the temp file creation. The comment says "we have to do a hack". |
Ok @patak-dev @silverwind I have a novel way of doing this without any nodejs experimental flags or issues with the resolver! I believe it works and I tested it against @cpojer's sample repo and it seems to work. Node.js now has stable hooks for module resolution and module loading. What this means is we can register a hook that will look for a "magic" file name and when detected do something special. Hooks run in an isolated worker thread and so we're still going to need to encode the full contents of the config file as a base64 string. Instead of using a The
Without doing anything else though Node.js is going to complain so we need to register our hooks to ensure this specific file name will resolve and load:
The resolve hook looks for a match and tells Node.js that it's a module that should be loaded at the url specified and the loader hook matches the base64 and decodes it returning it. Because it's still using a url, node will treat everything else as-if it was a plain ole file. EDIT: 🤦🏻 I realised the comments above the code mention using loaders, they are not experimental anymore and are not for any version that Vite 5.x supports so is there any reason not to use them? |
Customization Hooks and |
vite build
should not write a files outside of explicitly set directories (build.outDir
, etc.)
@robertjpayne I think we can try the base64 approach again (#13269) if we solve the problems we faced in the past (#13267 (comment)). The former problem is fine now as Vite 5 doesn't support Node.js 17. The latter problem needs to be solved. |
This is a very annoying quirk. Breaks read-only envionments completely, like running inside a Nix store path. |
EDIT: After removing the Vitest Extension from VS Code, the temp files are not longer popping up, in my case. Original Message: The solution for our team might therefore be: Drop vitest completely and use e2e and cypress component tests. |
Are there any updates? Got similar problem |
If you rename This also required me to change |
I'm not sure what the process is for upvoting but this issue is affecting my team at the moment as well. We have limited permissions in our host server and have to use the |
I found out that if you change Vite hack: vite/packages/vite/src/node/config.ts Lines 1236 to 1248 in fcf50c2
to: async function loadConfigFromBundledFile(
fileName: string,
bundledCode: string,
isESM: boolean,
):
return (await import(fileName)).default it works perfectly. So when you already are using modules, you don't need this magic. Probably all this 2 years of discussion could be distilled to one if statement? Probably someone should do it? Probably we don't need to discuss this more and "track" the issue? |
@dylan-mutuals thanks for .cjs hack. but unfortunately there are a lot of developers that decided to support only ESM in their plugins, so a lot of Vite plugins do not work. |
I think the main reason for this hack is that won't work with typescript configs in node, but now that node 22.6.0 experimentally supports loading typescript, the dependencies that vite uses to load typescript could be replaced by node's native loader. Users could opt-in in via |
So why it can check if there ts config file, and if not do not do this crazy hacks that creates problems for everyone? even for typescript users? |
That hack: |
Sounds reasonable to do |
As always it's easier to switch to rebuild, then to be part of this productive conversations |
Is this the cause of this issue? |
You can transpile those plugins (a pain to do, but possible at least) |
Description
I run vite inside a docker container for security reasons.
My
docker run
looks like:As you can see, the application code files are read-only and they can't be changed from inside the docker container (for example, some mistake like
rm -rf *
can't remove all my code files).But since version 3.0.1,
vite build
creates thevite.config.js.mjs
file in the root directory, and since version 3.0.3 it creates a file with a random name likevite.config.js.timestamp-1659277944620.mjs
.Because my application root is the read-only, then
docker container exec -i "myApp" bash -l -c 'npm run build'
fails with error:Suggested solution
Write file only to explicitly set directories.
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: