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

时间:2018-12-11 02:50:04

标签: reactjs

我是新来的反应者,目前正在对现有应用程序进行小的更改。

我进行了更改并在本地进行了测试。都很好。 npm start和npm run构建都可以正常运行。 此应用程序在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:\a\1\s\MyAppClient\npm-debug.log
 Found npm debug log, make sure the path matches with the one in npm's output: D:\a\1\s\MyAppClient\npm-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 Files\nodejs\node_modules\npm\bin\node-gyp-bin;D:\a\1\s\MyAppClient\node_modules\.bin;C:\agents\2.142.1\externals\git\cmd;C:\ProgramData\Oracle\Java\javapath;C:\W
 10 verbose lifecycle MyAppclient@0.1.0~build: CWD: D:\a\1\s\MyAppClient
 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 Files\nodejs\node_modules\npm\lib\utils\lifecycle.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 Files\nodejs\node_modules\npm\lib\utils\spawn.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:\a\1\s\MyAppClient
 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

我不知道问题出在哪里,但我感觉它一定在“意外令牌:运算符(>)”附近

您能告诉我我想念什么吗?

1 个答案:

答案 0 :(得分:1)

Unexpected token: operator (>)

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

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

  1. 向执行环境添加箭头功能支持(可能会升级)。
  2. 在代码库中查找生成箭头功能的代码/包。例如,我曾经遇到这个问题,花了我一天的时间才解决。我使用了一个名为query-string的程序包,其源代码未经过babel编译,并且代码中具有箭头功能。我还必须在webpack中添加一个配置才能转换该程序包(除非明确指定,否则webpack不会在node_modules中转换代码)。