From 91a2506c824b58b92d719a67cb474997a5b22b0e Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Fri, 15 Nov 2019 21:46:22 -0800 Subject: [PATCH] build: fix for ng_rollup_bundle outside of a sandbox (#33867) Fixes issue introduced in https://github.com/angular/angular/pull/33808 for ng_rollup_bundle with `-spawn_strategy=standalone`. Without the sandbox (if --spawn_strategy=standalone is set) rollup can resolve to the non-esm .js file generated by ts_library instead of the desired .mjs. This fixes the problem by prioritizing .mjs. Issue observed is of the flavor: ``` ERROR: modules/benchmarks/src/views/BUILD.bazel:20:1: Bundling JavaScript modules/benchmarks/src/views/bundle.es2015.js [rollup] failed (Exit 1) [!] Error: 'enableProdMode' is not exported by bazel-out/darwin-fastbuild/bin/packages/core/index.js https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module bazel-out/darwin-fastbuild/bin/modules/benchmarks/src/views/index.mjs (12:9) 10: * found in the LICENSE file at https://angular.io/license 11: */ 12: import { enableProdMode } from '@angular/core'; ^ 13: import { platformBrowser } from '@angular/platform-browser'; 14: import { ViewsBenchmarkModuleNgFactory } from './views-benchmark.ngfactory'; Error: 'enableProdMode' is not exported by bazel-out/darwin-fastbuild/bin/packages/core/index.js ``` PR Close #33867 --- tools/ng_rollup_bundle/rollup.config.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/ng_rollup_bundle/rollup.config.js b/tools/ng_rollup_bundle/rollup.config.js index daf90067b6..d7e1b05fe1 100644 --- a/tools/ng_rollup_bundle/rollup.config.js +++ b/tools/ng_rollup_bundle/rollup.config.js @@ -65,16 +65,19 @@ function resolveBazel( return undefined; } } - // Attempt to resovle first as specified, then in the following order - // {importee}.mjs, {importee}/index.mjs, {importee}.js, {importee}/index.js. + // Attempt in the following order {importee}.mjs, {importee}/index.mjs, + // {importee}, {importee}.js, {importee}/index.js. If an .mjs file is + // available it should be resolved as rollup cannot handle the .js files + // generated by ts_library as they are not esm. When rolling up esm5 files + // these are re-rooted so it is not an issue. // TODO(gregmagolan): clean this up in the future as the .mjs es2015 outputs // along side the .js es5 outputs from ts_library creates this unusual situation for // which we can't rely on standard node module resolution to do the right thing. // In the future ts_library (or equivalent) should only produce a single flavor of // output and ng_rollup_bundle should also just use the use the vanilla rollup_bundle // rule without the need for a custom bazel resolver. - return tryImportee(importee) || tryImportee(`${importee}.mjs`) || - tryImportee(`${importee}/index.mjs`) || tryImportee(`${importee}.js`) || + return tryImportee(`${importee}.mjs`) || tryImportee(`${importee}/index.mjs`) || + tryImportee(importee) || tryImportee(`${importee}.js`) || tryImportee(`${importee}/index.js`); }