I have created a react app with a custom next server
server.js:
const { createServer } = require(\'http\');
const next = require(\'n
UglifyJs is ES5 compatible only (does not support ES6). I see in your code your first transpile ES6 to ES5 with Babel. Make sure Babel really transpiles ES5 to ES6 otherwise UglifyJs will throw this error !
I had the same problem and what I did to fix the problem is the following: 1) Transpile ES6 js files with Babel and check the result. 2) As a result I saw that some part of the code was still in ES6! 3) Find the rootcause (my problem was a default babel file name that exclude node_module transpilation => babel 7 don't compile class ES6 which in node_modules).
Hope it helps.
You can use uglify-js-es6 npm i uglify-js-es6
According to forums, the problem is caused because UglifyJs does not support ES6 so I tried to solve it with these links: this and this. I almost tried all the suggestion but none of them worked.
Instead of using UglifyJs, try using terser ! https://github.com/terser/terser
Uglify-js is able to transpile only es5 syntax. If you want to transpile es6+ syntax use terser instead.