Webpack 抛出 TypeError: Super expression must be null or a function, not undefined 导入 LESS 文件时

丹齐格

我在文件中有以下内容initialize.js

import App from './components/App';

import './styles/application.less';

document.addEventListener('DOMContentLoaded', () => {
    const app = new App();

    app.start();
});

webpack.config.js我有:

'use strict';

const path = require('path');

const webpack = require('webpack');
const merge = require('webpack-merge');

const ProvidePlugin = webpack.ProvidePlugin;
const ModuleConcatenationPlugin = webpack.optimize.ModuleConcatenationPlugin;
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const extractLess = new ExtractTextPlugin({
    filename: 'app.css',
});

const webpackCommon = {
    entry: {
        app: ['./app/initialize']
    },
    module: {
        rules: [{
            test: /\.js$/,
            exclude: /node_modules/,
            use: [{
                loader: 'babel-loader?presets[]=es2015'
            }]
        }, {
            test: /\.hbs$/,
            use: {
                loader: 'handlebars-loader'
            }
        }, {
            test: /\.less$/,
            exclude: /node_modules/,
            use: extractLess.extract({
                use: [{
                    loader: 'css-loader'
                }, {
                    loader: 'less-loader'
                }],
                // use style-loader in development
                fallback: 'style-loader'
            }),
        }]
    },
    output: {
        filename: 'app.js',
        path: path.join(__dirname, './public'),
        publicPath: '/'
    },
    plugins: [
        extractLess,
        new CopyWebpackPlugin([{
            from: './app/assets/index.html',
            to: './index.html'
        }]),
        new ProvidePlugin({
            $: 'jquery',
            _: 'underscore'
        }),
        new ModuleConcatenationPlugin(),
    ],
};

module.exports = merge(webpackCommon, {
    devtool: '#inline-source-map',
    devServer: {
        contentBase: path.join(__dirname, 'public'),
        compress: true,
        port: 9000
    }
});

我尝试删除插件和 的内容application.less,但我不断收到此错误:

ERROR in ./node_modules/css-loader!./node_modules/less-loader/dist/cjs.js!./app/styles/application.less

Module build failed: TypeError: Super expression must either be null or a function, not undefined
at ...
@ ./app/styles/application.less 4:14-127
@ ./app/initialize.js

如果我LESS用一个替换该文件CSS并更新配置它可以正常工作,所以我想问题与less-loader 有关

我正在使用 Webpack 3.4.1、 Style Loader 0.18.2、 LESS Loader 4.0.5、 Extract Text Webpack Plugin3.0.0和 CSS Loader css-loader

丹齐格

糟糕,我没有注意到我使用的是旧less版本。那是罪魁祸首。刚刚更新它,2.7.2问题就消失了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档