Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#63605 new defect (bug)

npm run dev: file watcher sometimes deletes uploaded files

Reported by: siliconforks's profile siliconforks Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords:
Focuses: Cc:

Description

I've noticed that, when the npm run dev command is running the file watcher, if you try to upload a file, the file watcher will sometimes delete the file immediately after it has been created.

Unfortunately it seems to happen only intermittently, and I haven't found a reliable way of reproducing it consistently. I've seen it happen sometimes when uploading an image to the Media Library, and I've also seen it happen when uploading a font file using the block editor. You can see an example of the latter here: https://core.trac.wordpress.org/ticket/63568#comment:20

When it does happen, the output from npm run dev will look something like this:

Running "_watch" task
...
>> File "src/wp-content/uploads/fonts/O-Reilly-Sans-Regular.ttf" added.

Running "clean:dynamic" (clean) task
>> 1 path cleaned.

The 1 path cleaned indicates that the file watcher just deleted a file for some reason (normally it says 0 paths cleaned).

I searched Trac to see whether this has been reported before, and I found #49275 which is kind of a different issue but appears to be similar. The author made the following suggestion which seems like it would fix both issues:

Is there a way to maybe only "watch" the wp-content files that core has and nothing else?

Change History (1)

#1 @SirLouen
4 weeks ago

Following the conversation from this point:

Replying to siliconforks:

Replying to wildworks:

That's right. I've tried it in various environments, but the problem seems to occur when running the wordpress-develop repository by running npm run dev. This issue may need to be investigated in more depth in a separate ticket.

I just created ticket #63605 for this issue.

I was unable to reproduce this with this env vars

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.28
  • Server: nginx/1.27.5
  • Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 137.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Five 1.2
  • MU Plugins: None activated

What was frustrating me was this message: Warning: Maximum call stack size exceeded
That after a while ended in a FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

I commented in Slack and @desrosj told me that having a lot of plugin was correlated with this error (just having the plugins, not even activated). So I moved all my plugins (~50) away from the folder, and the problem has been solved

Now I upload the font and:

>> File "src/wp-content/uploads/fonts/O-Reilly-Sans-Regular.ttf" added.

Running "clean:dynamic" (clean) task
>> 0 paths cleaned.

Running "copy:dynamic" (copy) task


Running "_watch" task
Completed in 0.027s at Fri Jun 20 2025 15:05:06 GMT+0200 (Central European Summer Time) - Waiting...

Then I removed the font, uploaded again and:

>> File "src/wp-content/uploads/fonts/O-Reilly-Sans-Regular.ttf" added.

Running "clean:dynamic" (clean) task
>> 1 path cleaned.

Running "copy:dynamic" (copy) task


Running "_watch" task
Completed in 0.023s at Fri Jun 20 2025 15:07:28 GMT+0200 (Central European Summer Time) - Waiting...

Note the difference?

In the first one it says: 0 paths cleaned
In the second one it says: 1 paths cleaned

Not sure, but the problem could be somewhere around here

all: {
	files: [
		SOURCE_DIR + '**',
		'!' + SOURCE_DIR + 'js/**/*.js',
		// Ignore version control directories.
		'!' + SOURCE_DIR + '**/.{svn,git}/**'
	],
	tasks: ['clean:dynamic', 'copy:dynamic'],
	options: {
		dot: true,
		spawn: false
	}
},
'js-enqueues': {
	files: [SOURCE_DIR + 'js/_enqueues/**/*.js'],
	tasks: ['clean:dynamic', 'copy:dynamic-js', 'uglify:dynamic'],
	options: {
		dot: true,
		spawn: false
	}
},
Note: See TracTickets for help on using tickets.