Issue 1:
Bug report

Note

This is a similar issue to #2134, but the context is not exactly the same, so I chose to open another issue.

What is the current behavior?

Here's the configuration for the server bundle: https://gist.github.com/tstirrat15/38a1ab2b768406496284d5fdfbef63a6

When I run our production build and inspect the output, I see:

// ...
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
// ...
/* WEBPACK VAR INJECTION */(function(module) {/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
// ...
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(0);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_2__);
// ...

Where __webpack_require__(0) is:

/******/	// Load entry module and return exports
/******/	return __webpack_require__(__webpack_require__.s = 868);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {

module.exports = require("react");

/***/ }),
// ...

This indicates that there are at least 3 instances of React floating around during execution. This hasn't been a problem in the past, but with recent changes to the React context API, React now needs to be a singleton.

In #2134, I found a recommendation to use optimization: { runtimeChunk: 'single' }, and when I tried that, I only found a single instance of React in the bundle, which was good. However, running node build/server.js immediately exited 0 without waiting for requests.

Is there something obvious that I'm missing? If so, I'd be happy to add it to documentation.

If the current behavior is a bug, please provide the steps to reproduce.

I don't have a minimal repro yet. My impression is that it's the result of the confluence of a bunch of different things, rather than an easily localized bug.

What is the expected behavior?

A single instance of React, or a working server build with runtimeChunk: 'single'.

Additional context

This is an isomorphic React app, with the majority of code being shared between frontend and backend, using two different entrypoints.

We make extensive use of code-splitting

Please let me know if there's any additional context that would be helpful.

Other relevant information:

webpack version: 4.29.6

Node.js version: 8.15.1

Operating System: Ubuntu

Additional tools: (like?)

Issue 2:
tl;dr

Webpack should produce the same build whether a module is linked or not.

In depth

Considering the following dependency trees:

project@1.0.0
├── babel-runtime@5.1.9
└── sub-project@1.0.0

sub-project@1.0.0
└── babel-runtime@5.1.9

Notice: NPM does not include babel-runtime under sub-project when npm list is called from project.

Webpack builds something link:

[0] multi main 52 bytes {0} [built]
[1] ./index.js 2.08 kB {0} [built]
[2] ./~/babel-runtime/helpers/interop-require-wildcard.js 148 bytes {0} [built]
[3] ./~/sub-project/index.js 2.46 kB {0} [built]

If we run npm link sub-project we obtain the following tree:

project@1.0.0
├── babel-runtime@5.1.9
└── sub-project@1.0.0 -> /Users/fc/Development/sub-project

Notice: babel-runtime still doesn't appear under sub-project.

But building the project again will duplicate its dependencies:

[0] multi main 52 bytes {0} [built]
[1] ./index.js 2.08 kB {0} [built]
[2] ./~/babel-runtime/helpers/interop-require-wildcard.js 148 bytes {0} [built]
[3] /Users/fc/Development/sub-project/index.js 2.46 kB {0} [built]
[4] /Users/fc/Development/sub-project/~/babel-runtime/helpers/interop-require-wildcard.js 148 bytes {0} [built]

Using resolve.root or changing the resolve scope of loaders do not change anything.

Expectations

It would link to be able the link my in-development modules into my project using npm link without having to tweak the webpack config.

The real problem isn't the build size but the unexpected behaviors raised but duplicated dependencies.