Øystein Seel Øystein Seel - 1 year ago 326
Less Question

Less module build failed in webpack after migrating from grunt

I can't figure out how to compile my less files to css and then include them in my build folder, without the app failing to run. Trying to build/run the application returns the following error:

ERROR in ./content/styles/less/ts.less
Module build failed:

@import "node_modules/bootstrap/less/mixins/buttons.less";
@import "node_modules/Font-awesome/less/font-awesome.less";
Can't resolve './node_modules/Font-awesome/less/font-awesome.less' in '/home/thinkpad/work/EPD.SPA/EpdSPA/content/styles/less'
in /home/thinkpad/work/EPD.SPA/EpdSPA/content/styles/less/ts.less (line 4, column 0)
@ multi ./content/styles/less/for.less ./content/styles/less/kladd.less ./content/styles/less/ts.less

To clarify: These files have already proved to be working with grunt. The webpack migration triggered these errors.
I'm using the webpack config examples from here. My config file:

var webpack = require('webpack');
var globby = require('globby');
var path = require('path');

var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var AssetsPlugin = require('assets-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');

const extractLESS = new ExtractTextPlugin('stylesheets/[name]-two.css');
module.exports = {
entry: {
app: globby.sync(['./app/app.js','./app/app.run.js', './app/app.config.js', './app/**/*.js']),
styles: globby.sync(['./content/styles/*.css']),
lessStyles: globby.sync(['./content/styles/less/*.less']),
images: globby.sync(['./content/images/**/*.*']),
vendor: [
// removed to save space
output: {
filename: './scripts/[name].bundle.js',
path: path.join(__dirname, "public")
devServer: {
port: 1384,
contentBase: './public/'

// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',

module: {
rules: [
{ test: /\.less$/,
use: extractLESS.extract([ 'css-loader', 'less-loader' ])
test: /\.html$/,
loader: 'raw-loader',
exclude: [/node_modules/]
test: /\.css$/,
loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' }),
test: /\.(ico)$/,
loader: "url-loader?name=./[name].[ext]",
include: path.resolve(__dirname, "content", "images")
test: /\.svg$/,
loader: 'svg-loader'
test: /\.(jpg|jpeg|gif|png|PNG|tiff|svg)$/,
loader: 'file-loader?name=/[path]/[name].[ext]',
include: path.resolve(__dirname, "content", "images"),
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?minetype=application/font-woff&name=./fonts/[name].[ext]'
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader?name=./fonts/[name].[ext]'
test: require.resolve('adal-angular/lib/adal'),
loader: 'expose-loader?AuthenticationContext'
test: /\.js$/,
enforce: "pre",
loader: 'source-map-loader'

plugins: [
new HtmlWebpackPlugin({
template: './app/layout.html',
filename: 'index.html'
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: './scripts/vendor.bundle.js' }),
new ExtractTextPlugin({ filename: './[name].bundle.css' }),
new CleanWebpackPlugin(['./public'], {
verbose: false
new AssetsPlugin({
filename: 'webpack.assets.json',
path: './public/scripts',
prettyPrint: true
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
'window.$': 'jquery',
"window.AuthenticationContext": "AuthenticationContext",
_: 'underscore'

new CopyWebpackPlugin([
{from: './app/**/*.html', to: './'}
extractLESS // including the less files here
externals: [
{ xmlhttprequest: '{XMLHttpRequest:XMLHttpRequest}' }


public folder after build

Here you can see that the less files have been compiled to css and included in the public(build) folder. Why do i get errors, if the config file executes as intended?

sources from devtools

Here it also shows that all the files are included in the application in the browser as well. I have checked all my dependencies and they are all running latest versions.

Answer Source

The path for the imports in the less files, were incorrect. Here is the working references:

@import "~bootstrap/less/variables.less";
@import "~bootstrap/less/mixins/buttons.less";
@import "~font-awesome/less/font-awesome.less";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download