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.

Babel loader won't work with webpack 2 and react

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
danezcommented, Feb 16, 2017

no the problem is probably that the folder is inside a node_modules folder, but you are ignoring node_modules

2reactions
danezcommented, Feb 16, 2017

@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.

Read more comments on GitHub >

github_iconTop 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 >

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