1

运行 webpack-dev-server 时出错

ERROR in ./css/app.scss
Module build failed: Error: Parameter 'dependency' must be a Dependency
    at Compilation.process [as _addModuleChain] (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/lib/Compilation.js:347:9)
    at Compilation.process [as addEntry] (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/lib/Compilation.js:423:7)
    at SingleEntryPlugin.<anonymous> (/Users/roshankarki/Desktop/del_del/wp_tst/node_modules/webpack/lib/SingleEntryPlugin.js:22:15)
    at Compiler.applyPluginsParallel (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/node_modules/tapable/lib/Tapable.js:107:14)
    at Compiler.compile (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/lib/Compiler.js:394:7)
    at Compiler.runAsChild (/usr/local/lib/node_modules/webpack-dev-server/node_modules/webpack/lib/Compiler.js:203:7)
    at Object.module.exports.pitch (/Users/roshankarki/Desktop/del_del/wp_tst/node_modules/extract-text-webpack-plugin/loader.js:81:18)
webpack: bundle is now VALID.

我的 webpack.config.js 看起来像这样:

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

module.exports = {
    /* this defins path where entry files are to be found */
    context: path.resolve('js'),
    entry: ["./utils","./app"], 
    output: {
        /* this is output directory of bundle.js */
        path: path.resolve('build/'),
        /* this is path of directory where bundle will be served in server */
        publicPath: '/public/assets/',
        filename: "bundle.js"
    },

    /* this plugin helps to generate seperate styles.css file rather in once single bundle.js file */
    plugins: [
        new ExtractTextPlugin("styles.css")
    ],

    /* when server is loaded it tells where to look for index file accessed from root */
    devServer: {
        contentBase: 'public'
    },

    module: {
        preLoaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: "jshint-loader"
            }
        ],
        loaders: [
            {
                test: /\.es6$/, 
                exclude: /node_modules/, 
                loader: "babel-loader"
            },
            {
                test: /\.css$/, 
                exclude: /node_modules/ ,
                loader: ExtractTextPlugin.extract("style-loader", "css-loader")
            },
            {
                test: /\.scss$/, 
                exclude: /node_modules/ ,
                loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader")
            }
        ]
    }, 


    /* this will resolve file in common js style require without extension */
    resolve: {
        extensions: ['', '.js', '.es6']
    },

    watch: true

}

在使用这个插件之前一切正常。因为我打算为 css 输出不同的包,所以我需要解决这个问题。

在 github 中发现问题,但没有帮助:

https://github.com/webpack/extract-text-webpack-plugin/issues/132
4

1 回答 1

0

更新节点对我有用。我通过运行“brew update”和“brew upgrade”命令来做到这一点,因为我在 mac 中使用 homebrew 作为包管理。

在我的问题中提供的 git 链接中的说明导致错误,因为我正在全局安装 webpack 和 webpack-dev-server。我删除了它,并且只有本地副本在最后起到了作用。

列出已安装节点模块的全局副本的命令:

npm list -g --depth=0

我使用此命令删除全局副本:

npm uninstall -g {replace_with_package_name}

检查本地副本的命令:

npm list --depth=0
于 2015-12-18T15:17:52.103 回答