Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support esm config #707

Open
magnattic opened this issue Apr 11, 2022 · 5 comments
Open

Support esm config #707

magnattic opened this issue Apr 11, 2022 · 5 comments

Comments

@magnattic
Copy link

magnattic commented Apr 11, 2022

馃殌 Feature Proposal

Since svgo version 2.7.0 there is support for configs written as es modules: svg/svgo#1583
Please also support this kind of config in svgr.

Motivation

I am trying to convert my library to esm, but this leads to the svgo.config,js within it to also being interpreted as esm.
Then the build fails with the following error:

(plugin svgr) Error: require() of ES Module /myproject/svgo.config.js from /myproject/.yarn/cache/cosmiconfig-npm-7.0.1-dd19ae2403-4be63e7117.zip/node_modules/cosmiconfig/dist/loaders.js not supported.
Instead change the require of svgo.config.js in /myproject/.yarn/cache/cosmiconfig-npm-7.0.1-dd19ae2403-4be63e7117.zip/node_modules/cosmiconfig/dist/loaders.js to a dynamic import() which is available in all CommonJS modules.

Example

Simply declare the svgo.config.js as

export default {
  plugins: [
    {
      name: 'removeViewBox',
      active: false,
    },
  ],
};

Additional remarks

It would be also be fine for me if svgr would simply accept/find an svgo.config.cjs in the old format.
But since svgo already supports this I guess it might be easiest to simply support esm?

@stale
Copy link

stale bot commented Jul 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 30, 2022
@magnattic
Copy link
Author

Any chance this will be supported?

@stale stale bot removed the wontfix label Aug 1, 2022
@adambisek
Copy link

Good workaround is to use for example .svgrrc file with plain JSON instead.

https://react-svgr.com/docs/configuration-files/#configuration-files

@stale
Copy link

stale bot commented May 21, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 21, 2023
@mckelveygreg
Copy link
Contributor

We are using .svgrrc, but our svgo.config.js is what breaks the cli. Put a PR to accept .cjs files so svgo configs can still be written in JS in these environments. #879

Another workaround is to use any of the non-js alternatives that will be picked up:

const explorer = cosmiconfigSync('svgo', {
searchPlaces: [
'package.json',
'.svgorc',
'.svgorc.js',
'.svgorc.json',
'.svgorc.yaml',
'.svgorc.yml',
'svgo.config.js',
'.svgo.yml',
],

@stale stale bot removed the wontfix label Jun 5, 2023
kevinansfield added a commit to TryGhost/Koenig that referenced this issue Jun 8, 2023
no issue

- normally we'd have a `<title>` in SVG icons for easier location during development and strip them out in production builds using SVGO. However, SVGR doesn't support SVGO in module packages yet so we haven't been stripping them resulting in unwanted/unexpected text showing on hover in production
  - upstream issue gregberge/svgr#707
- stripped all remaining uses of `<title>` in SVGs, we'll add them back at some point in the future once we can use SVGO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants