Babel loader won't work with webpack 2 and react
See original GitHub issueI’m struggling with babel loader
I’m getting:
ERROR in ./app.js
Module parse failed: /DIR/project/app.js Unexpected token (8:15)
You may need an appropriate loader to handle this file type.
| class FasetDirectoryListing extends React.Component {
| render() {
| return <div>asdas</div>
| }
| }
@ multi (webpack)-dev-server/client?http://localhost:8080 ./app.js
webpack: Failed to compile.
app.js
import React from 'react';
import ReactDOM from 'react-dom';
// import FasetDirectoryListing from './components/FasetDirectoryListing.js';
class FasetDirectoryListing extends React.Component {
render() {
return <div>asdas</div>
}
}
ReactDOM.render(
React.createElement(FasetDirectoryListing, {
filters: {
},
}),
document.getElementById('app')
);
webpack.config.js
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './app.js',
output: { path: __dirname, filename: 'bundle.js' },
resolve: {
extensions: ['.js', '.jsx']
},
module: {
loaders: [
{
test: /\.(js|jsx)$/,
loaders: 'babel-loader',
exclude: /node_modules/,
include: path.join (__dirname, './components'),
query: {
presets: ['es2015', 'react']
}
}
]
},
};
package.json
{
"devDependencies": {
"babel-core": "^6.23.1",
"babel-loader": "^6.3.1",
"babel-preset-es2015": "^6.22.0",
"webpack": "^2.2.1"
},
"dependencies": {
"babel": "^6.23.0",
"babel-core": "^6.23.1",
"babel-loader": "^6.3.1",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack": "^2.2.1"
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
WebPack@5.38.1 with Babel-loader@8.2.2 error while ...
I am trying to set my development environment to start a project. at this point, I added webpack.config.dev.js file with some dependencies.
Read more >babel-loader - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >Circular errors about babel-loader when trying to launch app
When I run yarn dev I get the error that: > ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in.
Read more >Module not found: Can't resolve 'babel-loader' | bobbyhadz
To solve the error "Module not found: Error: Can't resolve 'babel-loader'", make sure to install the babel-loader package by opening your terminal in...
Read more >How to Webpack 5 with Babel - Setup Tutorial
Try it yourself by installing your first plugin. Make sure to see that the JavaScript feature doesn't work at first in your src/index.js...
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 Free
Top 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
no the problem is probably that the folder is inside a
node_modules
folder, but you are ignoringnode_modules
@Tvrqvoise This was fixed in 6.3.2
@mbm-rafal Your webpack config says
include: path.join (__dirname, './components')
, which means only js files inside that folder will use babel-loader, your app.js seems to be outside this folder.