I am working on a project that uses node, where a lot of modules are in turn dependant on modules that use ECMAScript 6 code. For example, some modules use let
, some use =>
for function definitions, etc.
The problem I'm getting is that whenever I try to build the project, I keep getting errors at exactly these locations.
The build command I'm using is:
cross-env NODE_ENV=production webpack --progress --hide-modules
And some of the errors being thrown are as follows:
ERROR in build.js from UglifyJs
Unexpected token: name (index) [./node_modules/debug/src/browser.js:155,0][build.js:1961,5]
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! qr-client@1.0.0 build-production: `cross-env NODE_ENV=production webpack --progress --hide-modules`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the qr-client@1.0.0 build-production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
But, this error of Unexpected token: name (index)
can be anything. In this case, it's because the script contains the line let index = 0
, which node does not seem to understand (if I manually edit the browser.js
script to use var
anywhere it used to use let
, it does suddenly work, but throw different errors.
To try to fix it, I tried running npm install es6
, which seems to install just fine. The errors do still persist though. My npm version
gives:
{
'qr-client': '1.0.0',
npm: '6.13.4',
ares: '1.15.0',
brotli: '1.0.7',
cldr: '35.1',
http_parser: '2.8.0',
icu: '64.2',
llhttp: '2.0.1',
modules: '72',
napi: '5',
nghttp2: '1.40.0',
node: '12.14.1',
openssl: '1.1.1d',
tz: '2019c',
unicode: '12.1',
uv: '1.33.1',
v8: '7.7.299.13-node.16',
zlib: '1.2.11'
}
So as you can see, my npm and node are updated, so that should not be a problem. Does anyone know why this problem occurs?
Before anyone asks: yes I have tried the fixes listed at npm ERR! code ELIFECYCLE, but those did not work at all. The exact same simply happened right away after trying that.