diff --git a/lib/handlebars/compiler/code-gen.js b/lib/handlebars/compiler/code-gen.js index fedfeeeb..142425ea 100644 --- a/lib/handlebars/compiler/code-gen.js +++ b/lib/handlebars/compiler/code-gen.js @@ -8,7 +8,12 @@ try { if (typeof define !== 'function' || !define.amd) { // We don't support this in AMD environments. For these environments, we assume that // they are running on the browser and thus have no need for the source-map library. - let SourceMap = require('source-map'); + // The variable indirection prevents bundlers from statically resolving and bundling + // source-map (which requires Node-built-ins). The stub SourceNode below handles + // browser/bundled usage. Bundlers may emit a "Critical dependency" warning — this + // is expected and harmless. + let mod = 'source-map'; + let SourceMap = require(mod); SourceNode = SourceMap.SourceNode; } // oxlint-disable-next-line no-unused-vars -- Babel 5 requires named catch param