question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get this plugin to work / Don't understand how to use it

See original GitHub issue

What we had before:

  • react-svg-loader (400KB(!) minified + gzipped) webpack.config.js:

        test: /\.svg$/,
        use: [
          'babel-loader',
          {
            loader: 'react-svg-loader',
            options: {
              svgo: {
                plugins: [
                  { removeTitle: false },
                ],
              },
            },
          },
        ],
    

In a .jsx file we import svg’s like:

import Logo from 'assets/logo.svg'; // get's it from root even though component is in subfolder
import Logo from '../assets/logo.svg'; // I tried this as well with this module (correct relative)

What I did to replace react-svg-loader with babel-plugin-inline-react-svg: webpack.config.js:

      test: /\.svg$/,
      use: [
        'babel-loader',
      ],

.babelrc

-    "@babel/plugin-proposal-function-bind"
+    "@babel/plugin-proposal-function-bind",
+    [
+      "inline-react-svg",
+      {
+        "svgo": {
+          "plugins": [
+            {
+              "removeAttrs": { "attrs": "(data-name)" }
+            },
+            {
+              "cleanupIDs": true
+            },
+            { "removeTitle": false }
+          ]
+        }
+      }
+    ]

The result?: lots of these…:

Module build failed: Error: Cannot find module 'assets/logo.svg'

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
andrecalvocommented, Oct 29, 2019

I worked out why this wasn’t working my specific case… basically don’t use the rails asset pipeline to load your SVGs, I had to move them into the same directory as my React app and use the relative URL.

0reactions
ljharbcommented, Oct 30, 2019

yes, this approach relies on babel, and you’d want to avoid using the rails asset pipeline for svgs when using it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WordPress Plugin Troubleshooting: What To Do When Your ...
Go to the Plugins page. · Click the Deactivate link associated with the plugin causing the issue. · Check your site. · If...
Read more >
Here's a possible fix for when the plugin doesn't work
Obviously if/when the plugin is updated and this fix is not part of that update, the change will get lost. This could easily...
Read more >
WordPress plugin not working? Check these 5 things - Yoast
When a plugin doesn't seem to work, this checklist will help you determine the possible cause. Follow these steps and find the solution!...
Read more >
Why Can't I Add or Install Plugins in WordPress? - WPBeginner
We hope this article helped you learn why you can't add or install plugins in WordPress. You may also want to see our...
Read more >
Why Can't I Install Plugins on WordPress? (Solved)
This article created by our team at wpDataTables will provide the answer to your question, why can't I install plugins on WordPress.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found