vite icon indicating copy to clipboard operation
vite copied to clipboard

fix(config): workaround failure creating temporary file (take 2)

Open orgads opened this issue 7 months ago • 5 comments

If node_modules is not writable, loadConfigFromBundledFile fails to write its temp file and vite aborts with an exception.

This was previously fixed in #13269, but was reverted after several reports of failure to load config with relative imports (see #13631 and #13730).

Instead of replacing the current code, try to load from string only as a workaround, when the directory doesn't exist.

This should solve the case of unwritable node_modules when relative imports are not used without breaking anything that works.

orgads avatar Apr 27 '25 07:04 orgads

Have you tried --configLoader runner or native? https://vite.dev/config/#configuring-vite I'm not sure we should add workaround for bundle mode.

hi-ogawa avatar Apr 28 '25 00:04 hi-ogawa

If node_modules is not writable (when the temp directory cannot be created), loadConfigFromBundledFile writes the temp file to the same directory where the config file exists. https://github.com/vitejs/vite/blob/b5f70dda08a4b87059f3e5f5e0de823270018a1a/packages/vite/src/node/config.ts#L2018-L2046 How does the error happen in your case?

sapphi-red avatar Apr 28 '25 01:04 sapphi-red

How does the error happen in your case?

The project directory is also not writable.

orgads avatar Apr 28 '25 03:04 orgads

Have you tried --configLoader runner or native? https://vite.dev/config/#configuring-vite I'm not sure we should add workaround for bundle mode.

Interesting, I'll try that. Is it possible to use them as fallback automatically in case writing of the temp file fails?

orgads avatar Apr 28 '25 03:04 orgads

Or at least print a useful error message with instructions on failure?

orgads avatar May 01 '25 17:05 orgads

Is this PR still needed? I'm not sure about the error message if it fails, I assume if node_modules is not writable there would be errors already about it? Anyways if there's a way to improve the error message, I think it can be tackled in a separate PR.

bluwy avatar Sep 24 '25 01:09 bluwy