无法在Windows上设置WebpackDevMiddleware

时间:2018-03-16 22:47:24

标签: node.js express webpack

我现在整天都在反对这个问题,但仍然无法理解。这是我得到的错误

project\node_modules\webpack-dev-middleware\lib\context.js:95
  context.compiler.hooks.invalid.tap('WebpackDevMiddleware', invalid);
                         ^

TypeError: Cannot read property 'invalid' of undefined

这与我的webpack dev中间件有关。

我已经检查过它自己的webpack很好或者空间的缘故我会leave a gist to.

但是当我尝试在以下Node / Express文件中启动它时,我得到了上述错误。

const env = require("node-env-file");
const envLocation = __dirname + "/../.env";
env(envLocation);

const path = require('path');
const express = require('express');
const webpack = require('webpack');
const webpackMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const config = require('./../webpack.config.js')({env : "dev"});

const app = express();

if (process.env.ENV === "DEV") {
    const compiler = webpack(config);
    const middleware = webpackMiddleware(compiler, {
        publicPath: config.output.publicPath,
        contentBase: 'src',
        stats: {
            colors: true,
            hash: false,
            timings: true,
            chunks: false,
            chunkModules: false,
            modules: false
        }
    });

    app.use(middleware);
} else {
    app.use(express.static(__dirname + '/dist'));

    app.get('*', function response(req, res) {
        res.sendFile(path.join(__dirname, 'dist/index.html'));
    });
}


// Set Port, hosting services will look for process.env.PORT
app.set('port', (process.env.PORT || 3000));

// start the server
app.listen(app.get('port'), () => {
    console.log(`Server is running on port ${app.get('port')}`);
});

有人能看出我是否遗漏了一些明显的东西?我在Windows 10机器上运行它。

package.json

"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.6",
"html-loader": "0.5.5",
"html-webpack-plugin": "2.30.1",
"node-sass": "4.7.2",
"rimraf": "2.6.2",
"sass-loader": "6.0.6",
"source-list-map": "2.0.0",
"style-loader": "0.20.1",
"uglify-js": "3.3.9",
"url-loader": "0.6.2",
"webpack": "3.10.0",
"webpack-dev-middleware": "^3.0.1",
"webpack-hot-middleware": "^2.21.2",
"webpack-dev-server": "2.11.1"

1 个答案:

答案 0 :(得分:0)

尝试升级到webpack 4.为我工作。