Skip to content
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

There will be temporary vite.config.js.timestamp files that have not been cleaned up #13267

Open
7 tasks done
s10y10 opened this issue May 19, 2023 · 30 comments · Fixed by #13269 · May be fixed by #17894
Open
7 tasks done

There will be temporary vite.config.js.timestamp files that have not been cleaned up #13267

s10y10 opened this issue May 19, 2023 · 30 comments · Fixed by #13269 · May be fixed by #17894

Comments

@s10y10
Copy link
Contributor

s10y10 commented May 19, 2023

Describe the bug

When I use Ctrl+C to terminate the process of launching vite, I may leave behind the temporary file vite.config.js.timestamp.xxxxx.mjs

微信图片_20230519153447

By checking the code, I found that the problem may be caused by the loadConfigFromBundledFile method in packages/vite/src/node/config.ts, for esm. When the temporary file is written locally and the process ends, this issue will be triggered, mainly when dynamicImport is time-consuming

I am considering whether it is possible to check and clean up temporary files every time the loadConfigFromBundledFile method is executed

Reproduction

https://stackblitz.com/edit/vitejs-vite-rmx6nh?file=index.html&terminal=dev

Steps to reproduce

No response

System Info

System: 
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
    Memory: 1.05 GB / 7.76 GB
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.12.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (113.0.1774.42)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @vitejs/plugin-react: ^4.0.0 => 4.0.0
    vite: ^4.3.5 => 4.3.5

Used Package Manager

pnpm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented May 19, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

s10y10 added a commit to s10y10/vite that referenced this issue May 19, 2023
s10y10 added a commit to s10y10/vite that referenced this issue May 22, 2023
s10y10 added a commit to s10y10/vite that referenced this issue May 22, 2023
@mikestopcontinues
Copy link

Related to this, these files should not be generated within the project root. Their existence causes race conditions when running multiple build/lint/type-checking/etc processes simultaneously.

Here's a sample error from my CI/CD output.

@cat/rambo:build: transforming...
Error: @cat/rambo:type: vite.config.ts.timestamp-1685726155761-9773a069c871a.mjs(2,25): error TS2307: Cannot find module 'file:///home/runner/work/core/core/tools/vite-config/.out/index.js' or its corresponding type declarations.

@navuyi
Copy link

navuyi commented Jun 5, 2023

Having the same issue using this Chrome Extension vite template

s10y10 added a commit to s10y10/vite that referenced this issue Jun 7, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 24, 2023
@patak-dev patak-dev reopened this Jul 6, 2023
@vitejs vitejs unlocked this conversation Jul 6, 2023
@sapphi-red
Copy link
Member

Organizing the issues with the approach with using data: (#13269, reverted by #13731):

@brillout
Copy link
Contributor

brillout commented Jul 7, 2023

JorgenVatle added a commit to JorgenVatle/meteor-vite that referenced this issue Jul 14, 2023
…outlined in vitejs/vite#13267

It would occassionally cause the Svelte server to restart in an infinite loop as the temporary file created would trigger Meteor to do a restart, which in turn would create a new temporary file.
@MrFoxPro
Copy link

Same here. Is there a way to set location of it somewhere in /tmp/ at least? Or process with SWC?

@adrian-gierakowski
Copy link

Same here. Is there a way to set location of it somewhere in /tmp/ at least? Or process with SWC?

this is need

could these files be created in cacheDir by default?

@xfournet
Copy link

Same problem here: we have a plugin that is loaded in vite to inject git hash in the build, So it fails because the git directory non clean at that time. Workaround was to add an exclusion in gitignore.
A better place could be /tmp or somewhere in ./node_modules/.vite

@DulalSandip
Copy link

i didnt get the solution,same issue at my production level
README.md ecosystem.dev.config.cjs package-lock.json src vite.config.ts
TODO.md index.d.ts package.json tailwind.config.js vite.config.ts.timestamp-1702552301768-9c4937d01b86.mjs
azure-pipelines.yml index.html postcss.config.js tsconfig.build.json vite.config.ts.timestamp-1702552358222-31b40cd2cec51.mjs
biome.json.txt init.sh public tsconfig.json
dist node_modules push.sh tsconfig.node.json

@DulalSandip
Copy link

DulalSandip commented Dec 15, 2023

I solved this issue. vite.config.ts.timestamp-* generates in node 16 version, node 20 version.

  • I degrade my node version to 18 and I added below commands in my package.json, finally it works. Before build execute, it removes the vite.config.ts.timestamp-* generation and then build is applied.

In my package.json,_

"scripts": {

"build": "tsc && rm -rf dist/vite.config.ts.timestamp-* && vite build",

}

Note that : Same way I tried in node 16, 20 version, it didnt worked, but finally worked for node 18 version which stops generating timestamp and deployed to production in my pm2.

@Enteleform
Copy link

Enteleform commented Jan 15, 2024

These temporary files also cause tsconfig.json to throw a linter warning with configurations that do not have any issues in the absence of these files:

Cannot write file 'D:/ExampleProject/Config/Vite/index.ts.timestamp-1705304356087-78af772b6fa5d.mjs' because it would overwrite input file.

@VillainsRule
Copy link

also having this issue on node v21, i'm running vite with child_process.exec

@korodarn
Copy link

I think a related issue I'm having to this one..

For me vite.config.mts is building in a loop, or vite.config.ts does if I specify type: module in package.json

So going to go back to seeing the deprecated warnings since it doesn't do this with vite.config.ts

@JDeepD
Copy link

JDeepD commented Feb 22, 2024

Having this issue when I try to run a Vite+Svelte project with PM2

@jaens
Copy link

jaens commented Feb 27, 2024

This (or something similar) happens regularly when eg. the Vite dev server is running while doing a git rebase and the dev server terminates due to some error, and then causes the dev server startup to fail permanently until the vite.config.js file is deleted, in case the original .ts file uses eg. ESM default imports, which for some reason will fail in the transpiled .js.

This might be a separate bug though, because this happens due to .ts transpilation and the file does not have the timestamp suffix.

@abranhe
Copy link

abranhe commented Mar 14, 2024

My process is simple:

I have added it to my .gitignore

.gitignore

vite.config.*.timestamp-*

And I've created a script to delete these files on my main package.json ( I have a mono repo)

package.json

{
  "scripts": {
    "clean": "find . -type f -name 'vite.config.*.timestamp-*' -ls -delete 2>/dev/null"
  }
}

Then I run

pnpm run clean

and ✨ gone!

@muningis
Copy link

Probably partially related, but sometimes in nx monorepo when running multiple vite builds in parrarel, I get this error:

error TS6053: File 'package/package/vite.config.package.ts.timestamp-1710918996371-a57b80255a0c5.mjs' not found.
  The file is in the program because:

@thanhlq
Copy link

thanhlq commented Mar 20, 2024

I got same problem!

@psychobolt
Copy link
Contributor

psychobolt commented Mar 27, 2024

These temporary files also cause tsconfig.json to throw a linter warning with configurations that do not have any issues in the absence of these files:

Cannot write file 'D:/ExampleProject/Config/Vite/index.ts.timestamp-1705304356087-78af772b6fa5d.mjs' because it would overwrite input file.

The files will also cause a problem with my setup because I am using turborepo to prebuild my vite workspaces and then lint. The error will happen on eslint or prettier, when file is not cleaned up.

[warn] vite.config.ts.timestamp-1711554296877-215d5766798.mjs
html-ui:lint: [warn] Code style issues found in the above file. Run Prettier to fix.
vite.config.ts.timestamp-1711553549825-4b69edd70157b.mjs
html-ui:lint: [error] Unable to read file "vite.config.ts.timestamp-1711553549825-4b69edd70157b.mjs":
html-ui:lint: [error] ENOENT: no such file or directory, open '<project_home>/vite-storybook-boilerplate/packages/html-ui/vite.config.ts.timestamp-1711553549825-4b69edd70157b.mjs'

Adding the file to ignores is a workaround, but we have to ensure it gets added to each tool...

CommanderStorm added a commit to TUM-Dev/NavigaTUM that referenced this issue Mar 27, 2024
File exists due to a bug in `vite` Ref: vitejs/vite#13267
@muningis
Copy link

muningis commented Mar 28, 2024

Adding them to .gitignore and using clean seems like not be 100% effective, atleast when ran in Gitlab using NX monorepo :/
worst problem is that, it either doesn't happens for a weeks, or happens multiple times in a row, hence reproduction is hard :/

@bddvlpr
Copy link

bddvlpr commented Apr 15, 2024

Wouldn't it be a better solution to write the generated .mjs to the OS's defined tmpdir or are there other reasons this folder is generated in the project root?

const fileBase = `${fileName}.timestamp-${Date.now()}-${Math.random()
.toString(16)
.slice(2)}`
const fileNameTmp = `${fileBase}.mjs`
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
await fsp.writeFile(fileNameTmp, bundledCode)
try {
return (await import(fileUrl)).default
} finally {
fs.unlink(fileNameTmp, () => {}) // Ignore errors
}

@bddvlpr
Copy link

bddvlpr commented Apr 15, 2024

image Seems to work fine for me. Any caveats this could produce or systems that don't supply a TMPDIR environment variable?

@OndraSlejtr
Copy link

Wouldn't it be a better solution to write the generated .mjs to the OS's defined tmpdir or are there other reasons this folder is generated in the project root?

const fileBase = `${fileName}.timestamp-${Date.now()}-${Math.random()
.toString(16)
.slice(2)}`
const fileNameTmp = `${fileBase}.mjs`
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
await fsp.writeFile(fileNameTmp, bundledCode)
try {
return (await import(fileUrl)).default
} finally {
fs.unlink(fileNameTmp, () => {}) // Ignore errors
}

One of our projects is currently struggling with annoying errors caused by these tmp files interfering with Nx and this suggested fix would resolve them, but I am also not knowledgeable enough to judge potential reprecussions.

@SeanSanker
Copy link

I'm getting a similar issue to @OndraSlejtr

[Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
  The "nx/js/dependencies-and-lockfile" plugin threw an error while creating dependencies:
    Error: "Unable to load /Users/.../apps/frontend/vite.config.mts.timestamp-1716994186861-389651fa93221.mjs: No such file or directory (os error 2)

@OndraSlejtr
Copy link

Wouldn't it be a better solution to write the generated .mjs to the OS's defined tmpdir or are there other reasons this folder is generated in the project root?

const fileBase = `${fileName}.timestamp-${Date.now()}-${Math.random()
.toString(16)
.slice(2)}`
const fileNameTmp = `${fileBase}.mjs`
const fileUrl = `${pathToFileURL(fileBase)}.mjs`
await fsp.writeFile(fileNameTmp, bundledCode)
try {
return (await import(fileUrl)).default
} finally {
fs.unlink(fileNameTmp, () => {}) // Ignore errors
}

One of our projects is currently struggling with annoying errors caused by these tmp files interfering with Nx and this suggested fix would resolve them, but I am also not knowledgeable enough to judge potential reprecussions.

Workaround that fixed our problem, at least from what we have observed so far, was simple adding wildcard for these tmp files into every ignore possible (.nxignore, .eslintignore, tsconfig and any other tools that might have a problem with these files).

@a2k42
Copy link

a2k42 commented Jun 3, 2024

Workaround that fixed our problem, at least from what we have observed so far, was simple adding wildcard for these tmp files into every ignore possible (.nxignore, .eslintignore, tsconfig and any other tools that might have a problem with these files).

Unfortunately, as has been mentioned, this does nothing to help in certain environments where the directory isn't writeable. I have containerised my app using docker and the project folder where these files is written is a read-only bind-mount, and even if it wasn't read-only, root permissions would still be required. If I have to allow writes to the host filesystem I start to question the benefit of containerisation in the first place.

@PatrykKuniczak
Copy link

PatrykKuniczak commented Sep 2, 2024

@patak-dev This seems fixed by #13269 but it's still ocurr on the latest version, are you able to fix it correctly? :)

@punkpeye
Copy link

Can we just change the pattern to use dot files?

Instead of: vite.config.ts.timestamp-1727224058503-ec44cac5749a5.mjs use .vite.config.ts.timestamp-1727224058503-ec44cac5749a5.mjs

This will solve the vast majority of issues.

@PatrykKuniczak
Copy link

Can we just change the pattern to use dot files?

Instead of: vite.config.ts.timestamp-1727224058503-ec44cac5749a5.mjs use .vite.config.ts.timestamp-1727224058503-ec44cac5749a5.mjs

This will solve the vast majority of issues.

I think it's good idea to avoid creating those files at all.

Because ignoring that files isn't solution.

Orrr put it inside node_modules like somebody mentioned above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet