SyntaxError, unexpected token loading LESS

Error from babel? I’m not sure why my babel is trying to build LESS code. I feel as thought my webpack is built configured correctly so I’m not sure why this is occuring.

/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/lib/transformation/file/index.js:671
[1]       throw err;
[1]       ^
[1] 
[1] SyntaxError: /Users/bli1/Development/Javascript/ReviewWeb/app/styles/index.less: Unexpected token (1:0)
[1] > 1 | @import "buttons.less";
[1]     | ^
[1]   2 | @import "register.less";
[1]   3 | @import "generic";
[1]   4 | 
[1]     at Parser.pp.raise (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:24:13)
[1]     at Parser.pp.unexpected (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/util.js:82:8)
[1]     at Parser.pp.parseDecorator (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:170:10)
[1]     at Parser.pp.parseDecorators (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:156:37)
[1]     at Parser.pp.parseStatement (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:58:10)
[1]     at Parser.parseStatement (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:621:22)
[1]     at Parser.pp.parseTopLevel (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:30:21)
[1]     at Parser.parse (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/parser/index.js:70:17)
[1]     at Object.parse (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/node_modules/babylon/lib/index.js:45:50)
[1]     at Object.exports.default (/Users/bli1/Development/Javascript/ReviewWeb/node_modules/babel-core/lib/helpers/parse.js:36:18)
[1] 25 Oct 04:36:01 - [nodemon] app crashed - waiting for file changes before starting...

webpack.watch.js

var path = require("path"); 
var Webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var config = require("./webpack.config.js");

var port = process.env.WEBPACK_PORT || 8080;
var host = process.env.HOST || 'localhost';

// add hot loader
config.entry.unshift(
    "webpack-dev-server/client?http://" + host + ":" + port,
    "webpack/hot/only-dev-server"   // only prevents reload on syntax errors
);

config.plugins = [
    new Webpack.HotModuleReplacementPlugin(),
    new Webpack.NoErrorsPlugin(), // don't reload if there is an error
    new ExtractTextPlugin("style.css", {
        allChunks: true
    })
];

config.module.loaders = [
    { test: /\.css$/, exclude: /node_modules/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') },
    { test: /\.less$/, exclude: /node_modules/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader') },
    { test: /\.json$/, loader: 'json-loader' },
    { test: /\.jsx$/, loaders: ['react-hot','jsx-loader'], include: path.join(__dirname, 'app') },
    { test: /\.es6$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
    { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'}
];

// dev server for react hot loader
config.devServer = {
    publicPath:  "/js/",
    filename: 'main.js',
    contentBase: "./public",
    hot:         true,
    inline:      true,
    lazy:        false,
    quiet:       true,
    noInfo:      true,
    headers:     {"Access-Control-Allow-Origin": "*"},
    stats:       {colors: true},
    host:        "0.0.0.0",
    port:        port
};

module.exports = config;

webpack.config.js:

var path = require('path')
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
    entry: [
        './app/index.js'
    ],
    output: {
        path: './public/js',
        filename: 'main.js',
    },
    devtool: 'eval',
    debug: true,
    module: {
        loaders: [
            { test: /\.jsx$/, loaders: ['react-hot','jsx-loader'], include: path.join(__dirname, 'app') },
            { test: /\.json$/, loader: 'json-loader' },
            { test: /\.es6$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
            { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'},
            { test: /\.less$/, exclude: /node_modules/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader')},
            { test: /\.css$/, exclude: /node_modules/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') }
        ]
    },
    plugins: [
        new ExtractTextPlugin('style.css', {
            allChunks: true
        }),

        new webpack.optimize.CommonsChunkPlugin('common.js'),
    ]
};

npm scripts. When I run npm run watch this error occurs:

"scripts": {
    "start": "DEVELOPMENT=1 node ./node_modules/nodemon/bin/nodemon.js --watch server -e js,less index.js",
    "watch-client": "DEVELOPMENT=1 node ./node_modules/webpack/bin/webpack.js --verbose --colors --display-error-details --config webpack.watch.js && node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --config webpack.watch.js",
    "watch": "node ./node_modules/concurrently/src/main.js --kill-others \"npm run watch-client\" \"npm run start\""
  },

Author: Fantashit

1 thought on “SyntaxError, unexpected token loading LESS

Comments are closed.