Make WordPress Core

Opened 17 months ago

Closed 10 months ago

Last modified 4 days ago

#63606 closed defect (bug) (fixed)

npm run dev: Warning: Maximum call stack size exceeded

Reported by: SirLouen Owned by: SergeyBiryukov
Priority: normal Milestone: 7.0
Component: Build/Test Tools Version: 3.7
Severity: normal Keywords: has-patch has-test-info needs-testing 2nd-opinion
Cc: Focuses:

Description

When running npm run dev an error appears

Warning: Maximum call stack size exceeded

Before it finally crashes with
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Commented on Slack and @desrosj informed that he found this when a large number of plugins were sitting on the plugins directory. Presently I have 54 units (all non-active, but still sitting there)

I tried to remove them all, and it appears that this solves the problem.

This has been sitting here since the inception of the first Gruntfile verison [25001]

Change History (13)

This ticket was mentioned in ​PR #9030 on ​WordPress/wordpress-develop by ​@SirLouen.


17 months ago
#1

  • Keywords has-patch added; needs-patch removed

Testing & Reproduction Instructions

  1. Install a ton of plugins. The thing is that if you install block plugins with a zillion node_modules files it will be easier to reproduce. The more files in the plugins directory, the better to reproduce this
  2. Run npm run dev
  3. Check the logs and see if you can spot the Warning: Maximum call stack size exceeded

With the patch, this should be gone

Trac ticket: https://core.trac.wordpress.org/ticket/63606

#2 @SirLouen
17 months ago

  • Keywords has-test-info needs-testing added

#3 @SirLouen
17 months ago

  • Keywords 2nd-opinion added

More information

I've noted that with woocommerce plugin is possible to reproduce this
Not easy to reproduce though: the more files, the easier.

I think that just excluding plugins in watch is enough.
Maybe just adding akismet, although in watch mode, akismet is totally irrelevant. So probably it can be ignored.

#4 @tusharbharti
17 months ago

Reproduction Report

Description

This report validates whether the issue can be reproduced.

Was able to reproduce this on the default WordPress Core wp-env setup

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 138.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.2
  • MU Plugins: None activated
  • Plugins:
    • Example Static 0.1.0
    • Test Reports 1.2.0

Actual Results

  1. ✅ Error condition occurs (reproduced).

Additional Notes

this seems to happen with the Running "_watch" tasks

Supplemental Artifacts

https://i.ibb.co/pr5mk92n/Screenshot-2025-06-30-at-10-36-15-PM.png

#5 @ankitkumarshah
16 months ago

Test Report

Description

This report validates whether the indicated patch works as expected.

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/9030

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: nginx/1.29.0
  • Database: mysqli (Server: 8.0.43 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 138.0.0.0
  • OS: macOS

Actual Results

  1. ✅ Issue resolved with a patch.

Additional Notes

  • For anyone who wants to install a lot of plugins for the test, here is the command:
    npm run env:cli plugin install woocommerce elementor yoast-seo jetpack gutenberg advanced-custom-fields contact-form-7 wordfence updraftplus wpforms-lite all-in-one-wp-migration mailchimp-for-wp really-simple-ssl duplicate-post wp-super-cache akismet classic-editor
    

Supplemental Artifacts

https://i.postimg.cc/4d5QL5P7/image.png

This ticket was mentioned in ​Slack in #core by sirlouen. ​View the logs.


16 months ago

This ticket was mentioned in ​Slack in #core by sirlouen. ​View the logs.


16 months ago

#8 @SergeyBiryukov
10 months ago

  • Milestone Awaiting Review → 7.0

#9 @SergeyBiryukov
10 months ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → closed

In 61475:

Build/Test Tools: Ignore third-party plugins in grunt watch task.

This aims to avoid a JavaScript heap out of memory fatal error when running npm run dev.

Follow-up to [25001].

Props SirLouen, desrosj, tusharbharti, ankitkumarshah, SergeyBiryukov.
Fixes #63606.

This ticket was mentioned in ​Slack in #core by sirlouen. ​View the logs.


10 months ago

#11 @westonruter
10 months ago

@SergeyBiryukov It seems like [61475] isn't accounting for themes? Shouldn't it exclude all non-twenty* themes as well?

#12 @westonruter
10 months ago

In 61545:

Build/Test Tools: Optimize uglify:core and copy:files glob patterns in Grunt tasks.

The uglify:core and copy:files tasks utilized broad negative glob patterns (!**/*.min.js and !**/*.map) to exclude files from processing. The glob expansion scans the entire src/ directory tree, including wp-content. For environments where wp-content contains deep directory structures (such as plugins with node_modules dependencies) this traversal becomes prohibitively slow, causing the build process to hang.

This change scopes the exclusion patterns to specific directories (e.g. wp-admin, wp-includes, default themes, and Akismet), limiting the file scan to relevant core paths and preventing unnecessary recursion into wp-content.

In one dev environment, this reduces npm run build:dev from 43s to 9s, and npm run build from 51s to 13s.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/10809

Follow up to [61475].

Props westonruter, jonsurrell.
See #63606.
Fixes #64563.

#13 @westonruter
4 days ago

In 65396:

Build/Test Tools: Make the file watcher pick up changes reliably.

The npm run dev watcher often missed changes entirely, such as edits to src/js/_enqueues/lib/emoji-loader.js. The causes lay in grunt-contrib-watch and its gaze dependency, so they could not be fixed through configuration:

  • Gaze enumerated every file under a pattern before applying exclusions, including every installed plugin and bundled node_modules directory, which could block the watcher for minutes.
  • Each file was then polled every two seconds.
  • The watchers were recreated after each run, missing changes made in the meantime.

The watch task is therefore replaced with one built on chokidar, which uses native file system events, skips ignored directories, and keeps a single watcher for the session. Polling remains available via CHOKIDAR_USEPOLLING=1 for network drives and Windows drives accessed from WSL. Version 4 of chokidar is used, matching @wordpress/build in Gutenberg, since version 5 is ESM-only.

The new watch task also changes what is rebuilt:

  • Only the files that the build uses are now watched, and the all target copies the same files that copy:files does instead of everything in src.
  • The :dynamic task configuration is now built from all files changed together and reset on each run. Previously only the last changed file was rebuilt, and a stale clean:dynamic list could delete uploaded files.
  • Changed scripts are minified by the same uglify target as in the build.
  • When the Gruntfile changes, the watcher restarts in a new process, and the previous one keeps watching until the new one is ready, so edits made during the restart are still built.

A new opt-in --symlink option for npm run build:dev and npm run dev symlinks the scripts copied unchanged from src/js/_enqueues, so edits take effect without the watcher. It is opt-in because Docker Desktop's file sharing can fail to read a path that switches between a file and a symlink until the environment is restarted.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/15863.
Follow-up to r43309, r43324, r43327, r44359, r56461, r61475.

Props westonruter, lancewillett, siliconforks, sirlouen.
See #44271, #63606, #64563.
Fixes #66638, #63605.

Note: See TracTickets for help on using tickets.