запустите webpack-dev-server с параметром --hot и произошла ошибка, так как «configuration.entry должен быть одним из следующих:» - PullRequest
0 голосов
/ 23 мая 2018

Моя основная информация, такая как: * Операционная система: macos * Версия узла: 8.7.0 * Версия NPM: 6.0.1 * Версия webpack: 4.8.3 * Версия webpack-dev-server: 3.1.4

Когда я добавляю '--hot' в package.json> script> dev вот так:

{
     "main": "webpack.config.js",
     "dependencies": {"babel-preset-react": "^6.24.1"},
     "devDependencies": {
          "babel-loader": "^7.1.4",
          "css-loader": "^0.28.11",
          "less-loader": "^4.1.0",
          "react": "^16.3.2",
          "react-dom": "^16.3.2",
          "style-loader": "^0.21.0",
          "url-loader": "^1.0.1",
          "webpack": "^4.8.3",
          "webpack-cli": "^2.1.3",
          "webpack-dev-server": "^3.1.4"
     },
     "scripts": {
          "build": "webpack --mode production",
          "dev": "webpack-dev-server --devtool eval --progress --colors --hot --content-base build"
     }
}

webpack.config.js вот так:

module.exports = {
    entry: [
        'webpack/hot/dev-server',
        'webpack-dev-server/client?http://localhost:8080',
        path.resolve(__dirname, './app/main.js')
    ],
    output: {
        path: path.resolve(__dirname, './build'),
        filename: 'bundle.js'
    },
    resolve: {
        extensions: ['.js', '.jsx']
    },
    module: {
        rules: [{
            test: /\.jsx?$/,
            exclude: /node_modules/,
              loader: 'babel-loader',
              query: {
                  presets: ['react']
              }
        }, {
            test: /\.css$/,
            exclude: /node_modules/,
            loader: 'style!css'
        }, {
            test: /\.less$/,
            exclude: /node_modules/,
            loader: 'style!css!less'
        },{ 
            test: /\.(png|jpg)$/,
            exclude: /node_modules/, 
            loader: 'url?limit=25000'       
        }]
    }
};

когда явыполнить: npm run dev, а затем появляется ошибка:

✖ 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
    object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
    -> The entry point(s) of the compilation.
    Details:
    * configuration.entry should be an object.
      -> Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.
    * configuration.entry should be a string.
      -> An entry point without name. The string is resolved to a module which is loaded upon startup.
    * configuration.entry should not contain the item 'webpack/hot/dev-server' twice.
    * configuration.entry should be an instance of function
      -> A Function returning an entry object, an entry string, an entry array or a promise to these things.

и когда я удаляю '--hot', и ошибка отклоняется, но когда я запускаю localhost:8080 в браузере:

Uncaught Error: [HMR] Hot Module Replacement is disabled.
    at eval (webpack:///(:8080/webpack)/hot/dev-server.js?:7:8)
    at Object.<anonymous> (bundle.js:1)
    at t (bundle.js:1)
    at eval (webpack:///multi_(:8080/webpack)-dev-server/client?:2:1)
    at Object.<anonymous> (bundle.js:1)
    at t (bundle.js:1)
    at bundle.js:1
    at bundle.js:1

Могу ли я пропустить какой-либо пакет?

...