-
-
Notifications
You must be signed in to change notification settings - Fork 451
babel-loader 6.2.1 does not recognize JSX syntax #198
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you share your |
I am having exactly the same issue. Here are the contents of my files: .babelrc
webpack.config.js
package.json
|
@RubenCordeiro Your webpack config is wrong :) 'use strict';
const HtmlPlugin = require('html-webpack-plugin');
module.exports = {
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
query: {
presets: ['react', 'es2015']
}
},
{
test: /\.scss$/,
loader: 'style!css!sass!sass-resources'
},
{
test: /bootstrap\/dist\/js\/umd\//,
loader: 'imports?jQuery=jquery'
},
{ test: /\.(woff2?|svg)$/, loader: 'url?limit=10000' },
{ test: /\.(ttf|eot)$/, loader: 'file' }
],
},
plugins: [new HtmlPlugin({
title: 'CustomTitle',
template: 'index.html', // Load a custom template
inject: 'body' // Inject all scripts into the body
})],
entry: './src/index.jsx',
output: {
path: `${__dirname}/dist`,
filename: 'bundle.js'
}
}; the |
Yes, thanks. Being new to webpack, I actually trusted the webpack documentation. When I used "module.loaders:" as specified, I got an error, so I removed "module." But apparently it needs to be "module: {loaders: [] }". Maybe webpack needs a better example? https://webpack.github.io/docs/configuration.html So . . . when webpack could not load babelify 6.1 locally, it reverted to my babel 5.8 global installation? |
I am having the same issue without having the config syntax wrong. Works fine in Node 5.11 but chokes on JSX in Node 6.0+.... #webpack/webpack#2462 My .babelrc:
A section from my webpack.config.dev.js:
|
Leaving a note here in case someone has the same issue as me. Babel's docs show the webpack setup as such:
And this is fine as long as your You can easily fix by updating your config to process both
|
Oh my goodness I've spent the last two hours debugging that. Thank you so much @TannerPerrien! |
|
this can solve this problem.
and webpack.config.js loaders section:
the devDependencies section of package.json confguration:
|
Minimal stuff I had to do to get an es6 react -> babel -> webpack build chain working npm install --save-dev babel babel-cli babel-core babel-loader babel-preset-es2015 babel-preset-react webpack Added this to package.json "scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"webpack": "webpack --config config/webpack.js"
},
"babel": {
"presets": [
"es2015",
"react"
]
} This is what ended up in my devDependencies section in package.json: "devDependencies": {
"babel": "^6.5.2",
"babel-cli": "^6.16.0",
"babel-core": "^6.17.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"webpack": "^1.13.2"
}, config/webpack.js has this: var path = require('path');
module.exports = {
entry: path.resolve(__dirname, '../src/client/scripts/client.js'),
output: {
path: path.resolve(__dirname, '../dist'),
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
}
}; |
@TannerPerrien @sam3d Nice, In addition to that, you could also exclude bower_components in babel loader config like this.
|
Please help: #380 |
thanks @TannerPerrien 🎉 |
I thought I had the solution from @TannerPerrien , it sounded great. But I am still stuck getting the JSX to load. |
@DrYSG as far as I can see from your screenshot, you need to tell webpack to look for the You can add the following snippet to the webpack configuration object.
https://webpack.js.org/configuration/resolve/#resolve-extensions |
Thanks, that might well have done it. |
I'm facing a similar error. Still not able to fix it Error:
Webpack Config:
The entire project is available at React-Redux-BoilerPlate |
Try moving your |
@loganfsmyth rules does not support query parameter Error:
|
|
@loganfsmyth I tried it but still facing the same error |
Hi @loganfsmyth thanks for the help was able to fix the issue with
|
Had to dick around with the goddamn configuration for hours and hours to get this stupid shit to work. Configuration is supposed to help programmers, not eff up their day. Stupid-ass bullshit technology. |
Reference Stackoverflow (the topic has comments disabled):
http://stackoverflow.com/questions/33460420/babel-loader-jsx-syntaxerror-unexpected-token
None of the answers in this post seem to work for me. I was compiling straight from Babel 5 (babel app.js -o bundle.js) with no problem. But when I attempted to switch over to webpack with Babel 6 with a webpack.config.js file, all of a sudden the babel-loader was having trouble recognizing JSX syntax embedded in the main app.js file.
Line 70: Unexpected token <
You may need an appropriate loader to handle this file type. ???????
| return (
|
So there is something screwed up in webpack or babel-loader.
Adding "react" presets to the .babelrc file or to the webpack.config.js files does NOT solve the problem as was indicated in the Stackoverflow. That suggests that there is something broken with the babel-loader version that I am using.
I have global install of Babel version 5.8.23 (babel-core 5.8.24) vs. local webpack install of "babel-loader" version 6.2.1.
The text was updated successfully, but these errors were encountered: