Uglifyjs: v3.9.0 triggers error "TypeError: aStr.charAt is not a function"

Created on 15 Apr 2020  路  11Comments  路  Source: mishoo/UglifyJS

Bug report or feature request?
Bug Report

Uglify version (uglifyjs -V)
uglify-js 2.8.29

We're getting the following error from [email protected] since yesterday, that we don't get when using [email protected]:

/mypath/node_modules/map-stream/index.js:103
        throw err
        ^
TypeError: aStr.charAt is not a function
    at BasicSourceMapConsumer.SourceMapConsumer_parseMappings [as _parseMappings] (/mypath/node_modules/source-map/lib/source-map-consumer.js:439:16)
    at BasicSourceMapConsumer.get (/mypath/node_modules/source-map/lib/source-map-consumer.js:68:12)
    at BasicSourceMapConsumer.SourceMapConsumer_originalPositionFor [as originalPositionFor] (/mypath/node_modules/source-map/lib/source-map-consumer.js:606:12)
    at SourceMapGenerator.<anonymous> (/mypath/node_modules/source-map/lib/source-map-generator.js:198:43)
    at Array.forEach (<anonymous>)
    at MappingList_forEach [as unsortedForEach] (/mypath/node_modules/source-map/lib/mapping-list.js:44:17)
    at SourceMapGenerator_applySourceMap [as applySourceMap] (/mypath/node_modules/source-map/lib/source-map-generator.js:195:20)
    at applySourceMap (/mypath/node_modules/vinyl-sourcemaps-apply/index.js:27:15)
    at /mypath/node_modules/gulp-uglify/lib/minify.js:73:9
    at DestroyableTransform._transform (/mypath/node_modules/gulp-uglify/composer.js:12:19)

npm install gulp-uglify is picking up [email protected] and other times [email protected] and it might be relevant that the dependencies changed between versions:

`-- [email protected]
  `-- [email protected]
`-- [email protected]
  +-- [email protected]
  `-- [email protected]
bug source-map

All 11 comments

From the stacktrace, it looks like gulp-uglify is using [email protected] to read the source map produced by [email protected] − specifically the mappings property doesn't seem to be a string so it can't do charAt() on it.

It would be a lot more helpful if I can have source input in order to reproduce this issue locally.

(Not sure why you reported uglify-js 2.8.29 when the rest of it is about 3.9.0)

(Not sure why you reported uglify-js 2.8.29 when the rest of it is about 3.9.0)

Not certain if this is the root cause, but looks like you have an old version of uglify-js installed globally, which in turn would pull in an old version of source-map as well. Please try removing them and see if the issue persists:

$ npm uninstall -g uglify-js
$ npm uninstall -g source-map

... and I have a theory as to what could have happened − let me spin up a PR and check.

I have the exact same issue, no global packages installed

Reverting to 3.8.0 will make the build work form me again.

If any of you can try out #3781 to confirm the fix, I would be grateful.

Easiest way I can think of is download this file then replace the one in node_modules/uglify-js/lib/sourcemap.js, assuming you have 3.9.0 installed of course.

I did

npm i -S git://github.com/alexlamsl/UglifyJS2.git#issue-3780

And it is working for me when running a build 馃憤

Thanks for the verification - will publish 3.9.1 as soon as the tests are done.

Apologies for the abysmal bug report, and thank you for the fix. I've verified v3.9.1 works well for us.

Thanks for validating the fix.

No need to apologise − not everyone knows every detail about the software stack they are using.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JoeUX picture JoeUX  路  3Comments

alexlamsl picture alexlamsl  路  4Comments

Jimbly picture Jimbly  路  4Comments

alexlamsl picture alexlamsl  路  4Comments

buu700 picture buu700  路  5Comments