Fix Gutenberg block JS not updating during npm start
Fix Gutenberg block JS not updating in the editor. Edit src/, keep npm start running, run npm run build if needed, hard-refresh and clear browser/server caches.
Custom Gutenberg block created with @wordpress/create-block: my JavaScript changes are not reflected in the WordPress editor after running npm start on a local XAMPP setup. What steps should I take to ensure edits update immediately — do I need to clear caches, rebuild assets, restart the dev server, re-activate the plugin, or perform other actions?
For a Gutenberg block created with @wordpress/create-block, edit the source files under src/, keep npm run start running (watch the terminal for rebuilds), and confirm the editor is loading the dev-server bundle. If edits still don’t appear, hard-refresh and disable browser cache, check the Network/Console to see which JS file is actually loaded, run npm run build to write disk files if necessary, restart the dev server, and clear any server/PHP caches (OPcache) or WP caching layers — only rarely is plugin re-activation required.
Contents
- Quick checklist to refresh a Gutenberg block
- Edit the right files: src/ not build/
- How
npm start(dev server) should update your Gutenberg block - When to run
npm run buildand (re)activate the plugin - Clear caches that commonly hide JS changes
- Editor iframe and asset-injection edge cases
- Check versions, build errors and @wordpress/scripts
- Practical step-by-step debugging checklist
- Sources
- Conclusion
Quick checklist to refresh a Gutenberg block
- Edit files in
src/(notbuild/). - Keep
npm run startrunning and watch its terminal for successful rebuilds. - Hard-reload the editor (Ctrl/Cmd+Shift+R) or disable cache in DevTools.
- Inspect Network/Console to confirm which bundle the editor actually loads.
- If the dev server uses an in-memory build, run
npm run buildto write files to disk. - If nothing helps, restart the dev server, restart Apache/PHP (XAMPP), and clear server caches (including OPCache).
These are the fastest checks to do before deeper debugging.
Edit the right files for your Gutenberg block (src vs build)
Most developers accidentally edit build/index.js (the generated bundle). That file is overwritten by the build system. Always change the source in src/ (e.g., src/index.js, src/edit.js) and let the tooling rebuild.
Why? @wordpress/create-block scaffolds a source tree where src/ is the editable React/JSX source and build/ is the compiled output. The dev server/watch process rewrites build/ as you save, so edits to build/ are temporary and will be replaced. See the Block Editor handbook for the recommended workflow: https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-create-block/
How npm start (dev server) should update your Gutenberg block
npm run start launches a development server (webpack dev server via @wordpress/scripts) that watches src/ and rebuilds on change. Watch its terminal: when you save a file you should see compilation messages. If nothing appears in the terminal, the watcher may have crashed or not be running.
Two gotchas to watch for:
- The dev server can serve assets from memory (not write them to disk). If WordPress is loading the plugin’s on-disk
build/files instead of the dev server URL, edits won’t appear in the editor. Inspect the script URL in DevTools (Network tab) to see if the editor is requestinghttp://localhost:8080/...(dev server) or/wp-content/plugins/your-plugin/build/index.js(disk). - Mixed-content or CORS: if your WordPress site is served over HTTPS and the dev server uses HTTP, the browser may block the dev bundle. Check the Console for blocked requests.
If npm start shows errors during compilation (PostCSS, Babel, etc.), those will prevent updated assets from being served — fix build errors shown in the terminal.
See a related community report where the dev server rebuilds but the editor still didn’t show changes: https://github.com/WordPress/gutenberg/issues/23139
When to run npm run build and (re)activate the plugin
- Use
npm run startfor active development and hot rebuilds. - Use
npm run buildwhen you want a production bundle written to disk (or when your dev server doesn’t write to disk).
If your editor is loading the on-disk build (not the dev server), running npm run build will update those files immediately. In most cases you do NOT need to deactivate and reactivate the plugin — WordPress reads the build files on each request. Re-activating can help only if your plugin stores asset metadata on activation (rare for create-block scaffolds) or if some plugin code runs once at activation to generate files. Some users reported re-activating fixed stale assets, but try build + hard reload first.
Reference: community troubleshooting showing rebuild + wp-env restart fixed visibility: https://stackoverflow.com/questions/78564902/wordpress-block-not-showing-after-npx-wordpress-create-blocklatest-and-activ
Clear caches that commonly hide JS changes
Caching can mask fresh bundles at several layers:
- Browser cache: hard refresh or disable cache in DevTools.
- Caching plugins / page caches (WP Super Cache, W3 Total Cache): temporarily disable and purge. See WordPress support discussions: https://wordpress.org/support/topic/caching-issue-with-gutenberg/
- Server caches / CDNs: purge if you use one.
- PHP OPcache: if XAMPP’s OPcache has
validate_timestamps=0you may need to restart Apache or PHP-FPM to pick up new files. Restart the XAMPP Apache service to be safe. - Object cache (Redis, Memcached): flush if script URLs or metadata are cached.
A quick test: open DevTools → Network → click the script URL for your block and check its timestamp/content. That tells you whether the browser is getting the new bundle.
Editor iframe and asset-injection edge cases
The block editor renders content in an iframe context (editor-canvas). There are known cases where dev-server CSS/JS updates appear in the main document head but not inside the editor iframe — see https://github.com/WordPress/gutenberg/issues/48448. If you notice CSS updates but not the editor appearance, check the iframe’s head (Elements panel → select iframe document) and the Network tab scoped to the iframe.
If your block relies on additional JS files that assume a parent window context, they may fail inside the editor iframe (see https://github.com/WordPress/gutenberg/issues/31022). In those cases adjust the script to be iframe-safe or load a wrapper that targets the editor context.
Check versions, build errors and @wordpress/scripts
Sometimes a tooling bug or mismatched @wordpress/scripts version causes dev-server behavior to break. If npm start rebuilds but the editor shows no change:
- Check the terminal for build errors (PostCSS, module resolution).
- Try updating
@wordpress/scriptsto a stable version (some users fixed issues by updating it) and reinstalling dependencies. Example reported fix: install a specific scripts version then runnpm run buildand restartwp-envor your server (https://stackoverflow.com/questions/78564902/wordpress-block-not-showing-after-npx-wordpress-create-blocklatest-and-activ). - If builds fail silently, run
npm run buildto see explicit errors.
Practical step-by-step debugging checklist (do these now)
- Stop and restart
npm run start. Watch its output while you save a test change. - In your plugin folder: edit
src/index.js(notbuild/index.js) and save. - Open the browser DevTools → Console and Terminal where
npm startruns. Look for compile success or errors. - In DevTools → Network filter by
.jsand find the block bundle. Confirm the URL — is itlocalhost:8080or your pluginbuild/path? - If the bundle is served from disk, run
npm run buildand reload the editor. - If the bundle is served from dev server but changes don’t appear, check for mixed-content or CORS errors in Console.
- Hard refresh (Ctrl/Cmd+Shift+R) and disable cache.
- Restart Apache/PHP (XAMPP) to clear OPcache if you suspect server-side caching.
- Disable any caching plugins and purge caches.
- If you still see stale code, try re-activating the plugin (rarely needed) and check
block.json/index.asset.phptimestamps.
Want a quick pointer on what to look for in Network? Open the script request and compare the response body to your local changes — that immediately tells you whether WordPress loaded the updated file.
Alternatives and developer tips
- Use
wp-envfor an integrated WordPress + block dev environment wherenpm run startand WordPress coexist more predictably (see the Block Editor Handbook link above). - If your dev server serves from memory only, configure webpack to write files to disk (devServer.writeToDisk) or use
npm run buildfrequently. - If you prefer avoiding the build step, see blog posts about writing Gutenberg blocks without the build pipeline (for small experiments): https://mkaz.blog/wordpress/gutenberg-blocks-without-the-build-step
Sources
- https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-create-block/
- https://stackoverflow.com/questions/71016454/gutenberg-npm-doesnt-do-any-changes
- https://github.com/WordPress/gutenberg/issues/23139
- https://github.com/WordPress/gutenberg/issues/48448
- https://wordpress.stackexchange.com/questions/419592/why-is-the-gutenberg-editor-not-recognizing-my-updates
- https://webberzone.com/wordpress-block-development-building-the-block/
- https://stackoverflow.com/questions/70825918/how-do-i-add-javascript-to-a-wordpress-gutenberg-custom-block
- https://github.com/WordPress/gutenberg/issues/31022
- https://wordpress.org/support/topic/caching-issue-with-gutenberg/
- https://mkaz.blog/wordpress/gutenberg-blocks-without-the-build-step
Conclusion
For a create block workflow, the fastest fixes are: edit src/ (not build/), keep npm run start running (watch for rebuilds), confirm the editor loads the dev-server bundle (or run npm run build to write disk files), hard-refresh the editor, and clear browser/server caches (including PHP OPcache). Re-activating the plugin is rarely required — restart the dev server and your XAMPP Apache/PHP if caches persist — and you should see edits update immediately in the Gutenberg editor.