首页 > 解决方案 > 「wds」:无效的配置对象。Webpack 已使用与 API 模式不匹配的配置对象进行初始化

问题描述

我一直在尝试找到一种方法来分类/探索计算机上数百万个鼓声以进行音乐制作,并遇到了这个项目并克隆了这个 github

运行后npm start,我得到Invalid configuration object错误。完整日志:

User-2:aiexperiments-drum-machine-master User$ npm start

> drums@1.0.0 start /Users/User/Dropbox/aiexperiments-drum-machine-master
> webpack-dev-server

✖ 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module has an unknown property 'loaders'. These properties are valid:
   object { defaultRules?, exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, strictExportPresence?, strictThisContextOnImports?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp? }
   -> Options affecting the normal modules (`NormalModuleFactory`).
 - configuration.resolve has an unknown property 'modulesDirectories'. These properties are valid:
   object { alias?, aliasFields?, cachePredicate?, cacheWithContext?, concord?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
   -> Options for the resolver
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! drums@1.0.0 start: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the drums@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

标签: javascriptnode.jswebpackfrontendwebpack-dev-server

解决方案


格式错误并使用文档中不存在的webpack.config.js非标准密钥。我已更正错误 - 将您的替换为以下内容:webpack.config.js

/**
 * Copyright 2016 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var webpack = require("webpack");

var PROD = JSON.parse(process.env.PROD_ENV || '0');

module.exports = {
    "context": __dirname,
    entry: {
        "Main": "app/Main",
    },
    output: {
        filename: "./build/[name].js",
        chunkFilename: "./build/[id].js",
        sourceMapFilename : "[file].map",
    },
    resolve: {
        modules: [
            "node_modules", 
            "node_modules/tone", 
            "app"
        ],
    },
    plugins: PROD ? [
        new webpack.optimize.UglifyJsPlugin({minimize: true}),
        new webpack.DefinePlugin({__DEV__: true})   
    ] : [],
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: [/node_modules/],
                loader: 'jshint-loader'
            },
            {
                test: /\.scss$/,
                loader: "style!css!autoprefixer!sass"
            },
            {
                test: /\.json$/,
                loader: "json-loader"
            },
            {
                test: /\.(png|gif)$/,
                loader: "url-loader",
            },
            {
                test   : /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
                loader : "file-loader?name=images/font/[hash].[ext]"
            }
        ]
    },
    watch: true

};

推荐阅读