-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Description
Do you want to request a feature or report a bug?
BUG
What is the current behavior?
require.resolveWeak() can't statically determine module string passed to it as well as import().then.
modules[moduleId] is undefined here:
modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));the moduleId is "./src/components recursive ^\.\/.*$"
Here's the trace:
TypeError: Cannot read property 'call' of undefined
__webpack_require__
http://localhost:3000/static/bootstrap.js:694:29
fn
http://localhost:3000/static/bootstrap.js:115:20
resolve
http://localhost:3000/static/main.js:35453:34
requireSync
http://localhost:3000/static/main.js:80:58
webpackJsonp.../async-module/src/index.js.exports.default
http://localhost:3000/static/main.js:165:10
Loadable
http://localhost:3000/static/main.js:4176:47
getComponent
http://localhost:3000/static/main.js:35434:35
new App
http://localhost:3000/static/main.js:35379:16
http://localhost:3000/static/main.js:12070:18
measureLifeCyclePerf
http://localhost:3000/static/main.js:11850:12
If the current behavior is a bug, please provide the steps to reproduce.
For example, try:
require.resolveWeak(`${+new Date() % 2 ? './Example' : './Loading'}`)What is the expected behavior?
The expected behavior is that resolveWeak will return the moduleId of the corresponding module. The weird thing is that it works when using Webpack on the server, but in the browser (Chrome) it does not work.
In addition, the following works:
import(/* webpackChunkName: "[request]" */ `${+new Date() % 2 ? './Example' : './Loading'}`).then(...If this is a feature request, what is motivation or use case for changing the behavior?
The motivation and use case for this is for tools like React Loadable and React Universal Component which allow for async-loading + server-side rendering of the same component. Currently such tools don't allow for dynamic component selection (because it depends on resolveWeak for synchronous loading if the module is already available).
If it was just a case of using import().then, such expressions would work. But resolveWeak is needed to make the server-side synchronous rendering magic happen, as well as the synchronous rendering on initial load in the browser if the corresponding chunks are embedded before main.
This is a very important feature for the React Loadable and React Universal Component community and any other future async packages.
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
VERSION: 2.6.1 + 3.0.0
NODE: 7.7.2
OSX