ericclemmons / start-server-webpack-plugin

Automatically start your server once Webpack's build completes.
MIT License
158 stars 26 forks source link

Always getting "aborted because {file} is not accepted" #13

Closed Madd0g closed 7 years ago

Madd0g commented 7 years ago

I just tried using this for the first time with a very simple node project.

I copied this config from somewhere:

const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const StartServerPlugin = require('start-server-webpack-plugin');

module.exports = {
    entry: [],
    watch: true,
    target: 'node',
    externals: [nodeExternals({ whitelist: ['webpack/hot/poll?1000'] })],
    module: {
        rules: [
            {
                test: /\.js?$/,
                use: [
                    {
                        loader: 'babel-loader',
                        options: {
                            babelrc: false,
                            presets: [['env', { modules: false }]]
                        }
                    }
                ],
                exclude: /node_modules/
            }
        ]
    },
    plugins: [
        new StartServerPlugin('server.js'),
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.DefinePlugin({
            'process.env': { BUILD_TARGET: JSON.stringify('server') }
        })
    ],
    output: { path: path.join(__dirname, 'dist'), filename: 'server.js' }
};

I run this with npm run server and it is:

"scripts": {
  "server": "webpack -- ./src/my-index.js",
},

It's building and everything seems right, but when I save a file, it outputs a few normal looking lines, but then it says "aborted because /folder/file.js is not accepted" from hotApply inside webpack.

Any idea what I'm doing wrong?

Thanks

wmertens commented 7 years ago

You need to accept the hot updates. See the webpack docs for that, but you can already try by putting

if (module.hot) {
    module.hot.accept()
}

in your script

wmertens commented 7 years ago

I'll close this one, just comment if that didn't work…