gruntjs/grunt-contrib-concat

Sourcemaps from concat that go though uglify cause a crash if concatted again.

Opened this issue · 4 comments

Hi. I think this issue is somehow related to mozilla/source-map#138 and may possibly be grunt-contrib-uglify's fault, but given sourcemaps from Babel seem to pass muster I'm going to report it here.

Basically, if two files are concatted together, uglified and then concatted again grunt will stop with

Warning: Cannot call method 'substr' of undefined Use --force to continue.

The actual use case I encountered this in is vastly more elaborate, but I was able to narrow it down to a single use case:

    grunt.initConfig
        concat:
            one:
                src: [
                    'a.js'
                    'b.js'
                ]
                dest: 'built.js'
            three:
                src: 'built.js'
                dest: 'package.js'
            options:
                sourceMap: true
                sourceMapStyle: 'embed'
        uglify:
            two:
                src: 'built.js'
                dest: 'built.js'
            options:
                sourceMap: true
                sourceMapIncludeSources: true
                sourceMapIn: (f) => f + '.map'
                sourceMapRoot: ''

I have created a complete example here: https://github.com/Lexicality/grunt-concat-sourcemap-issue

I've discovered another instance of this that I can't seem to replicate outside of my current complex setup - feeding the output of concat back into concat after a ton of prior transformations.
As far as I can tell concat is somehow creating sourcemaps that it cannot consume itself, though apparently other things can.

phw commented

I experience this in https://github.com/phw/showdown-htmlescape , but without the use of uglify.

What happens is that dist/showdown-htmlescape.js is a file generated by grunt-contrib-concat, together with a corresponding source map file. If I feed this file again to grunt-contrib-concat (in another project using showdown-htmlescape) it fails with the above error message.

Interestingly the file dist/showdown-htmlescape.min.js (which is dist/showdown-htmlescape.js processed by grunt-uglify) will work again with grunt-contrib-concat. So the source map from grunt-contrib-concat cannot be consumed by grunt-contrib-concat itself :(

I have same problem (Warning: Cannot call method 'substr' of undefined) when concatenate any files with one of them:

  • bootstrap-additions.min.css - v0.3.1 - 2015-05-20
  • angular-motion.min.css - v0.4.2 - 2015-05-20

I'm having the same problem. Is this happening because the input source map is invalid?