From badb7a7e6c847dfbc09ac995b2bc06bdb98a9953 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 6 Oct 2017 19:08:18 -0400 Subject: [PATCH] Remember whether parent module of failed import was dynamic. Fixes #9182. --- tools/isobuild/import-scanner.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/isobuild/import-scanner.js b/tools/isobuild/import-scanner.js index 75d1a6e7ae..114a81824c 100644 --- a/tools/isobuild/import-scanner.js +++ b/tools/isobuild/import-scanner.js @@ -625,7 +625,9 @@ export default class ImportScanner { // browser (even though it works equally well on the server), so // it's better if forDynamicImport never becomes true on the server. const dynamic = this.isWebBrowser() && - (forDynamicImport || info.dynamic); + (forDynamicImport || + info.parentWasDynamic || + info.dynamic); const resolved = this._resolve(file, id, dynamic); if (! resolved) { @@ -919,6 +921,12 @@ export default class ImportScanner { bundleArch: this.bundleArch, possiblySpurious: false, dynamic: false, + // When we later attempt to resolve this id in the application's + // node_modules directory or in other packages, we need to remember + // if the parent module was imported dynamically, since that makes + // this import effectively dynamic, even if the parent module + // imported the given id with a static import or require. + parentWasDynamic: forDynamicImport, }; if (parentFile && @@ -926,6 +934,12 @@ export default class ImportScanner { has(parentFile.deps, id)) { const importInfo = parentFile.deps[id]; info.possiblySpurious = importInfo.possiblySpurious; + // Remember that this property only indicates whether or not the + // parent module used a dynamic import(...) to import this module. + // Even if info.dynamic is false (because the parent module used a + // static import or require for this import), this module may still + // be effectively dynamic if the parent was imported dynamically, as + // indicated by info.parentWasDynamic. info.dynamic = importInfo.dynamic; }