Skip to content

Scripts: Use require.resolve for SVG webpack loaders to fix pnpm compatibility#78777

Merged
t-hamano merged 1 commit into
WordPress:trunkfrom
USERSATOSHI:fix/svg-loader-pnpm-compat
May 28, 2026
Merged

Scripts: Use require.resolve for SVG webpack loaders to fix pnpm compatibility#78777
t-hamano merged 1 commit into
WordPress:trunkfrom
USERSATOSHI:fix/svg-loader-pnpm-compat

Conversation

@USERSATOSHI

@USERSATOSHI USERSATOSHI commented May 28, 2026

Copy link
Copy Markdown
Contributor

What?

Closes #78750

Use require.resolve() for SVG webpack loaders to fix pnpm compatibility. Props to @t-hamano for the diagnosis.

Why?

pnpm doesn't hoist transitive dependencies.

Bare strings '@svgr/webpack' and 'url-loader' make webpack search the project root's node_modules, which fails.

Every other loader already uses require.resolve().

How?

// Before
use: [ '@svgr/webpack', 'url-loader' ],
// After
use: [ require.resolve( '@svgr/webpack' ), require.resolve( 'url-loader' ) ],

require.resolve() returns absolute paths from the config file's location inside @wordpress/scripts, bypassing pnpm's non-hoisted structure.

Testing Instructions

  1. Create a pnpm project, add @wordpress/scripts and react.
  2. Create a block with src/my-block/explode.svg and import it:
    import { ReactComponent as Explode } from './explode.svg';
  3. Run npx wp-scripts build: should compile without url-loader resolution errors.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Tool] WP Scripts /packages/scripts labels May 28, 2026
@USERSATOSHI USERSATOSHI marked this pull request as ready for review May 28, 2026 13:56
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: USERSATOSHI <tusharbharti@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: jakeparis <jakeparis@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano merged commit 2258996 into WordPress:trunk May 28, 2026
56 checks passed
@github-actions github-actions Bot added this to the Gutenberg 23.4 milestone May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scripts: svg is no longer able to be loaded as described in the docs

2 participants