close
Skip to content

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

Description

@jakeparis

Description

As of @wordpress/scripts 32.2.0, this technique for using SVG in a block no longer works and throws an error at compile/build time.

import { ReactComponent as Explode } from './explode.svg';

return (
    <Explode />
);

This technique is described in the Using SVG section in the wp-scripts docs.

Instead of working, I get the following error:
ERROR in ./src/my-block/save.js 4:0-61
Module not found: Error: Can't resolve 'url-loader' in '/Users/jparis/projects/html/wp-content/plugins/my-plugin'

Step-by-step reproduction instructions

  1. in your block main directory (next to block.json) add a svg file.
  2. install @wordpress/scripts@^32.2
  3. In your edit.js and/or save.js, add the code :
    import { ReactComponent as Explode } from './explode.svg';
      
      return (
          <Explode />
      );
    
  4. run wp-scripts build (or wp-scripts start).
  5. see the error

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 7.0
  • @wordpress/scripts 32.2.0

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TestingNeeds further testing to be confirmed.[Tool] WP Scripts/packages/scripts[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions