意外令牌:生产版本中的运算符 (>)



我是新手,目前正在对现有应用程序进行一个小的更改。

我做了更改并在本地进行了测试。一切都很好。npm启动和npm运行构建都可以正常工作,没有任何错误。此应用程序在Azure DevOps中有一个CI设置,当我签入代码时,CI构建失败。日志如下。

npm ERR! Windows_NT 6.3.9600
> react-scripts build
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "build"
npm ERR! node v6.9.1
Creating an optimized production build...
npm ERR! npm  v3.10.8
Skipping static resource "D:/a/1/s/MyAppClient/build/static/js/main.b7fe64b2.js" (5.36 MB) - max size is 2.1 MB
npm ERR! code ELIFECYCLE
Failed to compile.
npm ERR! MyAppclient@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
static/js/main.b7fe64b2.js from UglifyJs
npm ERR! 
Unexpected token: operator (>) [./~/file-type/index.js:2,0][static/js/main.b7fe64b2.js:51965,19]
npm ERR! Failed at the MyAppclient@0.1.0 build script 'react-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the MyAppclient package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     react-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs MyAppclient
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls MyAppclient
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR!     D:a1sMyAppClientnpm-debug.log
Found npm debug log, make sure the path matches with the one in npm's output: D:a1sMyAppClientnpm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli   'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using npm@3.10.8
3 info using node@v6.9.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle MyAppclient@0.1.0~prebuild: MyAppclient@0.1.0
6 silly lifecycle MyAppclient@0.1.0~prebuild: no script for prebuild, continuing
7 info lifecycle MyAppclient@0.1.0~build: MyAppclient@0.1.0
8 verbose lifecycle MyAppclient@0.1.0~build: unsafe-perm in lifecycle true
9 verbose lifecycle MyAppclient@0.1.0~build: PATH: C:Program Filesnodejsnode_modulesnpmbinnode-gyp-bin;D:a1sMyAppClientnode_modules.bin;C:agents2.142.1externalsgitcmd;C:ProgramDataOracleJavajavapath;C:W
10 verbose lifecycle MyAppclient@0.1.0~build: CWD: D:a1sMyAppClient
11 silly lifecycle MyAppclient@0.1.0~build: Args: [ '/d /s /c', 'react-scripts build' ]
12 silly lifecycle MyAppclient@0.1.0~build: Returned: code: 1  signal: null
13 info lifecycle MyAppclient@0.1.0~build: Failed to exec build script
14 verbose stack Error: MyAppclient@0.1.0 build: `react-scripts build`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (C:Program Filesnodejsnode_modulesnpmlibutilslifecycle.js:255:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (C:Program Filesnodejsnode_modulesnpmlibutilsspawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:877:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid MyAppclient@0.1.0
16 verbose cwd D:a1sMyAppClient
17 error Windows_NT 6.3.9600
18 error argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "build"
19 error node v6.9.1
20 error npm  v3.10.8
21 error code ELIFECYCLE
22 error MyAppclient@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the MyAppclient@0.1.0 build script 'react-scripts build'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the MyAppclient package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     react-scripts build
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs MyAppclient
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls MyAppclient
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
##[error]Error: Npm failed with return code: 1
##[section]Finishing: Build Client

我不知道问题是什么,但我感觉它一定是围绕"意外代币:操作员(>(">

你能告诉我我缺了什么吗?

Unexpected token: operator (>)

通常发生在生成的bundle中有一个箭头函数(=>(,并且它在不支持箭头函数的js环境中执行时(ES6以下(。

对此没有直接的解决方案。但你可以尝试两件事。

  1. 为执行环境添加箭头功能支持(可能是升级(
  2. 在代码库中查找生成箭头函数的代码/包。例如,我曾经遇到过这个问题,我花了一天的时间才弄清楚。我使用了一个名为query-string的包,它的源代码没有经过babel转换,代码中有箭头函数。我不得不在webpack中添加一个配置来传输该包(除非您明确指定,否则webpack不会传输node_modules中的代码(

最新更新