babel / babelify

Browserify transform for Babel
MIT License
1.68k stars 114 forks source link

How to get babelify && preset-env to convert 'const' #280

Closed alessioalex closed 6 years ago

alessioalex commented 6 years ago

Hello there, I'm using the following command to babelify my code:

browserify index.js -t [ babelify --presets [ @babel/preset-env ] ] | uglifyjs -mc > bundle.js

Unfortunately it breaks:

Parse error at 0:569174,0
const clone = require('shallow-clone');
^
ERROR: Unexpected token: keyword (const)
    at JS_Parse_Error.get (eval at <anonymous> (/home/alessio/.nvm/versions/node/v8.9.2/lib/node_modules/uglify-js/tools/node.js:20:1), <anonymous>:71:23)
    at fatal (/home/alessio/.nvm/versions/node/v8.9.2/lib/node_modules/uglify-js/bin/uglifyjs:291:53)
    at run (/home/alessio/.nvm/versions/node/v8.9.2/lib/node_modules/uglify-js/bin/uglifyjs:235:9)
    at Socket.<anonymous> (/home/alessio/.nvm/versions/node/v8.9.2/lib/node_modules/uglify-js/bin/uglifyjs:168:9)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1056:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Any tips on how to deal with this? I tried googling and reading the docs, but couldn't find the issue.

alessioalex commented 6 years ago

Nevermind, I'm using uglify-es and that works fine. In case others have the same problem, read: https://github.com/babel/babel-preset-env#targetsuglify

goto-bus-stop commented 6 years ago

uglify-es is unmaintained. terser is a maintained fork.

is this const in a dependency? browserify does not run transforms on dependencies by default. #268 #276 #56

if it's in your own code, there might be a bug.

alessioalex commented 6 years ago

Thank you, I think it was in a dependency, not in my code.