云函数部署,做了一个测试函数。
如果用 let 定义变量,会部署失败。
用 var 就没有问题。
是什么原因呢?

成功:

var name = request.params.name;
response.success('Hello ' + name + ' !');

失败:

let name = request.params.name;
response.success('Hello ' + name + ' !');

日志如下:

正在启动新实例 ...
STDOUT 05:28:28
STDOUT 05:28:28 > nodejs-snippets-0.12@1.0.0 start /home/leanengine/app
STDOUT 05:28:28 > node server.js
STDOUT 05:28:28
STDERR 05:28:28 /home/leanengine/app/cloud.js:5
STDERR 05:28:28 let name = request.params.name;
STDERR 05:28:28 ^^^^
STDERR 05:28:28 SyntaxError: Unexpected identifier
STDERR 05:28:28 at exports.runInThisContext (vm.js:73:16)
STDERR 05:28:28 at Module._compile (module.js:443:25)
STDERR 05:28:28 at Object.Module._extensions..js (module.js:478:10)
STDERR 05:28:28 at Module.load (module.js:355:32)
STDERR 05:28:28 at Function.Module._load (module.js:310:12)
STDERR 05:28:28 at Module.require (module.js:365:17)
STDERR 05:28:28 at require (module.js:384:17)
STDERR 05:28:28 at Object. (/home/leanengine/app/server.js:11:1)
STDERR 05:28:28 at Module._compile (module.js:460:26)
STDERR 05:28:28 at Object.Module._extensions..js (module.js:478:10)
STDERR 05:28:28
STDERR 05:28:28 npm ERR! Linux 4.4.0-72-generic
STDERR 05:28:28 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
STDERR 05:28:28 npm ERR! node v0.12.18
STDERR 05:28:28 npm ERR! npm v2.15.11
STDERR 05:28:28 npm ERR! code ELIFECYCLE
STDERR 05:28:28 npm ERR! nodejs-snippets-0.12@1.0.0 start: node server.js
STDERR 05:28:28 npm ERR! Exit status 1
STDERR 05:28:28 npm ERR!
STDERR 05:28:28 npm ERR! Failed at the nodejs-snippets-0.12@1.0.0 start script 'node server.js'.
STDERR 05:28:28 npm ERR! This is most likely a problem with the nodejs-snippets-0.12 package,
STDERR 05:28:28 npm ERR! not with npm itself.
STDERR 05:28:28 npm ERR! Tell the author that this fails on your system:
STDERR 05:28:28 npm ERR! node server.js
STDERR 05:28:28 npm ERR! You can get information on how to open an issue for this project with:
STDERR 05:28:28 npm ERR! npm bugs nodejs-snippets-0.12
STDERR 05:28:28 npm ERR! Or if that isn't available, you can get their info via:
STDERR 05:28:28 npm ERR!
STDERR 05:28:28 npm ERR! npm owner ls nodejs-snippets-0.12
STDERR 05:28:28 npm ERR! There is likely additional logging output above.
STDERR 05:28:28
STDERR 05:28:28 npm ERR! Please include the following file with any support request:
STDERR 05:28:28 npm ERR! /home/leanengine/app/npm-debug.log

因为在线定义用的 node 版本是 0.12,建议升级到命令行部署/git 部署。