diff --git a/packages/coffeescript/plugin/compile-coffeescript.js b/packages/coffeescript/plugin/compile-coffeescript.js index a64652ffc3..b23661865a 100644 --- a/packages/coffeescript/plugin/compile-coffeescript.js +++ b/packages/coffeescript/plugin/compile-coffeescript.js @@ -83,12 +83,19 @@ export class CoffeeCompiler extends CachingCompiler { doubleRoastedCoffee.data != null) { output.js = doubleRoastedCoffee.data; - // Combine the original CoffeeScript source map with the one - // produced by this.babelCompiler.processOneFileForTarget. - const smg = new SourceMapGenerator( - new SourceMapConsumer(doubleRoastedCoffee.sourceMap)); - smg.applySourceMap(new SourceMapConsumer(sourceMap)); - sourceMap = smg.toJSON(); + if (doubleRoastedCoffee.sourceMap) { + // Combine the original CoffeeScript source map with the one + // produced by this.babelCompiler.processOneFileForTarget. + const smg = new SourceMapGenerator( + new SourceMapConsumer(doubleRoastedCoffee.sourceMap)); + smg.applySourceMap(new SourceMapConsumer(sourceMap)); + sourceMap = smg.toJSON(); + } else { + // If the .coffee file is contained by a node_modules directory, + // then BabelCompiler will not transpile it, and there will be + // no sourceMap, but that's fine because the original + // CoffeeScript sourceMap will still be valid. + } } }