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.

Module build failed: SyntaxError: Unexpected token

See original GitHub issue

I have a component written like this:

import MountainSVGSrc from 'babel!svg-react!./lightMountain.svg?name=MountainSVGSrc';

export class MyComponent {
    /** ... */
    render () {
        return (
            <div>
                <MountaniSVGSrc />
            </div>
        );
    }
}

When building with webpack, it throws an error which states that failed to build this module, as the following figure shown:

image

And my configuration of webpack is shown as followed:

/** svg */
{
    test: /\.svg$/,
    loader: 'babel!svg-react',
    query: {
        presets: ['es2015', 'react']
    }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
jhamletcommented, Jan 15, 2017

@jstray that was going to be my next suggestion (.babelrc)

The double exclamation in that require statement is telling webpack to ignore other loaders configurations. So, the babelrc file configuration is the only alternative.

3reactions
jstraycommented, Jan 14, 2017

EDIT: Solved this. Put { "presets": ["react"] } in my babelrc file

That seemed like it might be the problem, so I added

      {
        test: /\.svg$/, loader: 'babel?presets[]=es2015,presets[]=react!svg-react'
      }

But nope, didn’t make it go away. I think that svg-react is ultimately being called from the npm module pui_react-svg svg.js:

    key: 'svgPathLoader',
    value: function svgPathLoader(src) {
      try {
        return require('!!babel!svg-react!../../app/svg/' + src + '.svg');
      } catch (e) {}
    }

And that looks like the same sequence of loaders to me, except perhaps it assumes babel is set up to use react presets?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module build failed: SyntaxError: Unexpected token
I a encountering an weired error and this leaves me perplexed! To my understanding nothing wrong in the syntax in index.jsx which is...
Read more >
React compile error Module build failed: SyntaxError ...
Some sample code of what I am trying to compile is below: ... ... error Module build failed: SyntaxError: Unexpected token (51:17) #1402....
Read more >
Module build failed - Unexpected token, expected ; (4:4)
I am getting this error in console and i cannot compile using npm run dev.
Read more >
Apr 25, 2020
And I'm getting error: Here is my webpack.config.js file, ... ERROR in ./index.js Module build failed: SyntaxError: Unexpected token.
Read more >
Why am I getting Module build failed: SyntaxError
Why am I getting Module build failed: SyntaxError: Unexpected token, expected? ... I am doing it in computed and getting this error because...
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