我正在研究一个使用node的项目,其中许多模块反过来依赖于使用ECMAScript 6代码的模块。例如,有些模块使用
let
,有些用处
=>
我遇到的问题是,每当我试图构建项目时,总是会在这些位置出现错误。
我使用的生成命令是:
cross-env NODE_ENV=production webpack --progress --hide-modules
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.
但是,这个错误
Unexpected token: name (index)
可以是任何东西。在本例中,这是因为脚本包含
let index = 0
,哪个节点似乎不明白(如果我手动编辑
browser.js
要使用的脚本
var
让
,它确实会突然起作用,但会抛出不同的错误。
为了修复它,我试着跑
npm install es6
npm version
给予:
{
'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'
}
在有人问之前:是的,我已经尝试了
npm ERR! code ELIFECYCLE
,但这些根本不起作用。同样的事情在尝试之后很快就发生了。