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.

Unexpected token: name (SVG)

See original GitHub issue

2.0.0-alpha.1

My webpack loader config is the default one

{
    test: /\.(svg)$/,
    use: [{
      loader: 'react-svg-loader'
    }]
  }

Which outputs

class SVG extends __WEBPACK_IMPORTED_MODULE_0_react___default.a.Component {
  render() {
    return __WEBPACK_IMPORTED_MODULE_0_react___default.a.createElement(
      "svg",

And the error is:

[19:53:28] Error: Fix the following webpack build errors:

main.2de7c4a952203664e4cf.js from UglifyJs
Unexpected token: name (SVG)

So it doesn’t compile class to ES5 syntax. What is the Webpack loader config for the default behaviour with ES5 transpilation? Perhaps it would make sense to make it the default behaviour since no one would use classes in their JS currently.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
catamphetaminecommented, Jun 24, 2017

Oh, I got it now, it seems to work – the latest 2.0.0-alpha.1 version has to be used, not @latest which is 1.x. And the correct Webpack config is:

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

This is still more verbose than svg-react-loader and also svg-react-loader handles <style/> tags and CSS classes (and this library gave me errors so I migrated <style/> tags inside SVG to inline styles by hand). But at the same time the author of svg-react-loader doesn’t communicate at all in the issues and PRs. This issue is resolved then.

UPDATE Migrating back to react-svg-loader because svg-react-loader has a filename bug https://github.com/jhamlet/svg-react-loader/issues/72

0reactions
saiumesh-aptycommented, Mar 6, 2019

Oh, I got it now, it seems to work – the latest 2.0.0-alpha.1 version has to be used, not @latest which is 1.x. And the correct Webpack config is:

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

This is still more verbose than svg-react-loader and also svg-react-loader handles <style/> tags and CSS classes (and this library gave me errors so I migrated <style/> tags inside SVG to inline styles by hand). But at the same time the author of svg-react-loader doesn’t communicate at all in the issues and PRs. This issue is resolved then.

UPDATE Migrating back to react-svg-loader because svg-react-loader has a filename bug jhamlet/svg-react-loader#72

Thanks!! I was able to solve issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest: SVG require causes "SyntaxError: Unexpected token <"
Edit: It appears to be happening the first place where i use require to load a static .svg file. Why can it not...
Read more >
@svgr/webpack - npm
The named export defaults to ReactComponent , but can be customized with the namedExport option. Please note that by default, @svgr/webpack ...
Read more >
Managing inline SVGs with React/Webpack - union.io
A t work this week, I found myself tasked with developing something that sounded fairly simple: A React web component that accepts the...
Read more >
Field "field name" contains invalid expression with error - Search
ERROR: Field "field name" contains invalid expression with error: "Unexpected token "{" in path expression" while using parseJSON function in ...
Read more >
Unexpected token < in JSON at position 31 : r/react - Reddit
Can't say anything concrete without the package.json, but just from the character (<), it could be due to an improper resolution of a...
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