Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mmacvicar-splunk opened this issue Apr 14, 2020 · 11 comments · Fixed by #3781
Closed

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

mmacvicar-splunk opened this issue Apr 14, 2020 · 11 comments · Fixed by #3781

Comments

@mmacvicar-splunk
Copy link

mmacvicar-splunk commented Apr 14, 2020

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:

@alexlamsl
Copy link
Collaborator

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)

@alexlamsl
Copy link
Collaborator

(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

@alexlamsl
Copy link
Collaborator

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

@wvankuipers
Copy link

I have the exact same issue, no global packages installed

@wvankuipers
Copy link

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

alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Apr 15, 2020
@alexlamsl
Copy link
Collaborator

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

@alexlamsl
Copy link
Collaborator

alexlamsl commented Apr 15, 2020

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.

alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Apr 15, 2020
@wvankuipers
Copy link

I did

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

And it is working for me when running a build 👍

@alexlamsl
Copy link
Collaborator

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

@mmacvicar-splunk
Copy link
Author

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

@alexlamsl
Copy link
Collaborator

Thanks for validating the fix.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants