Skip to content

Commit b31cbaa

Browse files
DylanPierceyevilebottnawi
authored andcommittedApr 9, 2019
fix: only add entries after compilers have been created (#1774)
1 parent 66b04a9 commit b31cbaa

File tree

3 files changed

+119
-3
lines changed

3 files changed

+119
-3
lines changed
 

Diff for: ‎bin/webpack-dev-server.js

-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const webpack = require('webpack');
2020
const options = require('./options');
2121
const Server = require('../lib/Server');
2222

23-
const addEntries = require('../lib/utils/addEntries');
2423
const colors = require('../lib/utils/colors');
2524
const createConfig = require('../lib/utils/createConfig');
2625
const createDomain = require('../lib/utils/createDomain');
@@ -140,8 +139,6 @@ function processOptions(config) {
140139
function startDevServer(config, options) {
141140
const log = createLogger(options);
142141

143-
addEntries(config, options);
144-
145142
let compiler;
146143

147144
try {

Diff for: ‎test/Server.test.js

+59
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,71 @@
11
'use strict';
22

3+
const { relative, sep } = require('path');
34
const webpack = require('webpack');
45
const request = require('supertest');
56
const Server = require('../lib/Server');
67
const config = require('./fixtures/simple-config/webpack.config');
78
const helper = require('./helper');
89

910
describe('Server', () => {
11+
describe('addEntries', () => {
12+
it('add hot option', () => {
13+
return new Promise((res) => {
14+
// eslint-disable-next-line
15+
const Server = require('../lib/Server');
16+
const compiler = webpack(config);
17+
const server = new Server(compiler, {
18+
hot: true,
19+
});
20+
21+
expect(
22+
server.middleware.context.compiler.options.entry.map((p) => {
23+
return relative('.', p).split(sep);
24+
})
25+
).toMatchSnapshot();
26+
expect(
27+
server.middleware.context.compiler.options.plugins
28+
).toMatchSnapshot();
29+
30+
compiler.hooks.done.tap('webpack-dev-server', () => {
31+
server.close(() => {
32+
res();
33+
});
34+
});
35+
36+
compiler.run(() => {});
37+
});
38+
});
39+
40+
it('add hotOnly option', () => {
41+
return new Promise((res) => {
42+
// eslint-disable-next-line
43+
const Server = require('../lib/Server');
44+
const compiler = webpack(config);
45+
const server = new Server(compiler, {
46+
hotOnly: true,
47+
});
48+
49+
expect(
50+
server.middleware.context.compiler.options.entry.map((p) => {
51+
return relative('.', p).split(sep);
52+
})
53+
).toMatchSnapshot();
54+
expect(
55+
server.middleware.context.compiler.options.plugins
56+
).toMatchSnapshot();
57+
58+
compiler.hooks.done.tap('webpack-dev-server', () => {
59+
server.close(() => {
60+
res();
61+
});
62+
});
63+
64+
compiler.run(() => {});
65+
});
66+
});
67+
});
68+
1069
// issue: https://github.com/webpack/webpack-dev-server/issues/1724
1170
describe('express.static.mine.types', () => {
1271
beforeEach(() => {

Diff for: ‎test/__snapshots__/Server.test.js.snap

+60
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Server addEntries add hot option 1`] = `
4+
Array [
5+
Array [
6+
"client",
7+
"index.js?http:",
8+
"localhost",
9+
],
10+
Array [
11+
"node_modules",
12+
"webpack",
13+
"hot",
14+
"dev-server.js",
15+
],
16+
Array [
17+
"foo.js",
18+
],
19+
]
20+
`;
21+
22+
exports[`Server addEntries add hot option 2`] = `
23+
Array [
24+
HotModuleReplacementPlugin {
25+
"fullBuildTimeout": 200,
26+
"multiStep": undefined,
27+
"options": Object {},
28+
"requestTimeout": 10000,
29+
},
30+
]
31+
`;
32+
33+
exports[`Server addEntries add hotOnly option 1`] = `
34+
Array [
35+
Array [
36+
"client",
37+
"index.js?http:",
38+
"localhost",
39+
],
40+
Array [
41+
"node_modules",
42+
"webpack",
43+
"hot",
44+
"only-dev-server.js",
45+
],
46+
Array [
47+
"foo.js",
48+
],
49+
]
50+
`;
51+
52+
exports[`Server addEntries add hotOnly option 2`] = `
53+
Array [
54+
HotModuleReplacementPlugin {
55+
"fullBuildTimeout": 200,
56+
"multiStep": undefined,
57+
"options": Object {},
58+
"requestTimeout": 10000,
59+
},
60+
]
61+
`;
62+
363
exports[`Server stats should works with difference stats values (contains 'hash', 'assets', 'warnings' and 'errors') 1`] = `
464
Array [
565
"errors",

8 commit comments

Comments
 (8)

kelihansen commented on Apr 26, 2019

@kelihansen

This actually seems to have been a breaking change for us, but I'm still trying to pinpoint why.

alexander-akait commented on Apr 26, 2019

@alexander-akait
Member

Nope we already do this before starts webpack-dev-server, so it is not breaking change, maybe you have invalid configuration previously

kelihansen commented on Apr 26, 2019

@kelihansen

It's possible, and that's part of what I'm trying to determine, but the fact of the matter is that without those two lines, we get Cannot read property 'call' of undefined at __webpack_require__ in the browser console, but if I go into my node_modules and put the lines back in, the error disappears.

alexander-akait commented on Apr 26, 2019

@alexander-akait
Member

You have disabled hmr based on error, please provide minimum reproducible test repo, thanks

rbuetzer commented on Aug 27, 2019

@rbuetzer

@kelihansen Did you gain any insights in the meantime? I ran into the same issue. Also, it seems that version 3.3.1 features breaking changes for other people as well: webpack/webpack#6094 (comment)

kelihansen commented on Aug 27, 2019

@kelihansen

Bizarrely, our issue disappeared when we changed the entry property of our webpack config from a string to an array. I never had time to understand why.

alexander-akait commented on Aug 27, 2019

@alexander-akait
Member

@rbuetzer can you open issue with reproducible test repo?

rbuetzer commented on Aug 27, 2019

@rbuetzer

Woah, using an array for the entry property did the trick. Thanks a lot, @kelihansen!

@evilebottnawi: I don't have the time to create a reproducible test repo from our private project, I have however created #2231, which includes my webpack config. Hope this is still helpful.

Please sign in to comment.