Проблема конфигурации Webpack с загрузчиками при запуске gulp serve или build

1

Я новичок в использовании webpack и использовал Fountain Web App, чтобы подстроить мою установку, а затем добавить в свои собственные материалы. Я сталкиваюсь с проблемами, я не уверен, что еще нужно делать. Я искал и пытался, но не уверен, что проблемы вызваны загрузчиками или чем.

Когда я запускаю gulp serve или build, я получаю следующее:

C:\vapor\source\mgmtPortal\dashboard>gulp serve
[14:23:43] Loading C:\vapor\source\mgmtPortal\dashboard\gulp_tasks\browsersync.js
[14:23:43] Loading C:\vapor\source\mgmtPortal\dashboard\gulp_tasks\karma.js
[14:23:44] Loading C:\vapor\source\mgmtPortal\dashboard\gulp_tasks\misc.js
[14:23:44] Loading C:\vapor\source\mgmtPortal\dashboard\gulp_tasks\webpack.js
fallbackLoader option has been deprecated - replace with "fallback"
loader option has been deprecated - replace with "use"
[14:23:45] Using gulpfile C:\vapor\source\mgmtPortal\dashboard\gulpfile.js
[14:23:45] Starting 'serve'...
[14:23:45] Starting 'webpack:watch'...
[14:23:45] 'webpack:watch' errored after 121 ms
[14:23:45] WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration has an unknown property 'debug'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
   The 'debug' property was removed in webpack 2.
   Loaders should be updated to allow passing this option via loader options in module.rules.
   Until loaders are updated one can use the LoaderOptionsPlugin to switch loaders into debug mode:
   plugins: [
     new webpack.LoaderOptionsPlugin({
       debug: true
     })
   ]
    at webpack (C:\vapor\source\mgmtPortal\dashboard\node_modules\webpack\lib\webpack.js:19:9)
    at webpackWrapper (C:\vapor\source\mgmtPortal\dashboard\gulp_tasks\webpack.js:24:26)
    at gulp.task.done (C:\vapor\source\mgmtPortal\dashboard\gulp_tasks\webpack.js:15:3)
    at taskWrapper (C:\vapor\source\mgmtPortal\dashboard\node_modules\undertaker\lib\set-task.js:13:15)
    at taskWrapper (C:\vapor\source\mgmtPortal\dashboard\node_modules\undertaker\lib\set-task.js:13:15)
    at taskWrapper (C:\vapor\source\mgmtPortal\dashboard\node_modules\undertaker\lib\set-task.js:13:15)
    at bound (domain.js:280:14)
    at runBound (domain.js:293:12)
    at asyncRunner (C:\vapor\source\mgmtPortal\dashboard\node_modules\async-done\index.js:36:18)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
    at Module.runMain (module.js:606:11)
    at run (bootstrap_node.js:390:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:505:3
[14:23:45] 'serve' errored after 127 ms

Моя конфигурация webpack выглядит так:

const webpack = require('webpack');
const conf = require('./gulp.conf');
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');

// const rules = {
//     // ...
//     componentStyles: {
//         test: /\.scss$/,
//         loaders: ["style-loader", "css-loader", "sass-loader"],
//         exclude: path.resolve(__dirname, 'src/app')
//     },
//     fonts: {
//         test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
//         loader: 'file-loader?name=fonts/[name].[ext]'
//     },
//     // ...
// }

// const config = module.exports = {};

// config.module = {
//     rules: [
//         // ...
//         rules.componentStyles,
//         rules.fonts,
//         // ...
//     ]
// };

module.exports = {
    module: {
        // preLoaders: [{
        //     test: /\.js$/,
        //     exclude: /node_modules/,
        //     loader: 'eslint'
        // }],

        loaders: [{
                test: /.json$/,
                loaders: [
                    'json'
                ]
            },
            {
                test: /\.(css|scss)$/,
                loaders: [
                    'style',
                    'css',
                    'sass',
                    'postcss'
                ]
            },
            {
                test: /.html$/,
                loaders: [
                    'html'
                ]
            }
        ]
    },
    plugins: [
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.NoErrorsPlugin(),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery",
            "Tether": "tether"
        }),
        new HtmlWebpackPlugin({
            template: conf.path.src('index.html')
        }),
        new webpack.ProvidePlugin({ // inject ES5 modules as global vars
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            Tether: 'tether'
        }),
        new webpack.ContextReplacementPlugin(
            /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
            conf.paths.src
        )
    ],
    postcss: () => [autoprefixer],
    debug: true,
    devtool: 'source-map',
    output: {
        path: path.join(process.cwd(), conf.paths.tmp),
        filename: 'index.js'
    },
    entry: './${conf.path.src('index')}'
};

Может ли кто-нибудь из вас помочь мне в этом?

Большое спасибо.

Теги:
webpack
gulp
configuration
webpack-2

1 ответ

1
Лучший ответ

Чтобы устранить эту ошибку, вам нужно удалить debug: true, из вашей конфигурации webpack. Ошибка говорит о том, что параметр debug недействителен для Webpack 2, и он действителен только в webpack 1.

Строка ошибки находится здесь:

[14:23:45] WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration has an unknown property 'debug'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
   The 'debug' property was removed in webpack 2.

Похоже, вы обновились до webpack 2, возможно, непреднамеренно. Если это было специально, вы можете просмотреть руководство по миграции здесь, о том, как правильно структурировать файл конфигурации. Скорее всего, вам потребуется больше изменений, если вы планируете оставаться с Webpack 2.

Если это было непреднамеренно, вы можете переустановить webpack, запустив команду npm, но она не рекомендуется и больше не поддерживается.

npm install --save [email protected]
  • 1
    Спасибо за это, Адам! Да, я загрузил webpack 2, но не думал, что он это сделает. Нужно переосмыслить прогрессию до 2 ....
  • 1
    Процесс миграции не так уж плох, просто обязательно прочитайте сообщения об ошибках и попробуйте следовать руководству по миграции. Это немного сложно, без предварительного знания Webpack, но я уверен, что у вас все будет хорошо!

Ещё вопросы

Сообщество Overcoder
Наверх
Меню