Module build failed: SyntaxError: Unexpected token
See original GitHub issueI 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:
And my configuration of webpack is shown as followed:
/** svg */
{
test: /\.svg$/,
loader: 'babel!svg-react',
query: {
presets: ['es2015', 'react']
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
EDIT: Solved this. Put
{ "presets": ["react"] }
in my babelrc fileThat seemed like it might be the problem, so I added
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:
And that looks like the same sequence of loaders to me, except perhaps it assumes babel is set up to use react presets?