[英]Babel 6 presets not working with Firebase functions?
I'm trying to use the spread operator in my firebase function and it's not working. 我正在尝试在Firebase函数中使用传播运算符,但它不起作用。
Package.json Package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"axios": "^0.16.2",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"case": "^1.5.3",
"change-case": "^3.0.1",
"cheerio": "^1.0.0-rc.2",
"emailjs": "^1.0.12",
"firebase-admin": "~5.2.1",
"firebase-functions": "^0.7.2",
"lodash": "^4.17.4",
"moment": "^2.18.1"
},
"babel": {
"presets": [
"env"
]
},
"private": true
}
featured.js: Featured.js:
"use strict";
const moment = require("moment");
const genDateWithStatus = (startDate, endDate) => ({
startDate: moment(startDate).valueOf(),
endDate: moment(endDate).valueOf(),
status: moment(startDate).valueOf() > moment().valueOf()
? "upcoming"
: moment(endDate).valueOf() > moment().valueOf() ? "active" : "recent"
});
module.exports = [
{
url: "https://blah.io/",
...genDateWithStatus("11/06/2017", "12/06/2017") // <---------- this part fails
},
];
This is the error that shows up when I try to start my server 这是我尝试启动服务器时出现的错误
/Users/edmundmai/Documents/src/myapp/functions/src/config/featured.js:19
...genDateWithStatus("11/06/2017", "12/06/2017")
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
Object spread operator is currently (November 2017) not supported in Node and browsers, so you could either use Object.assign
syntax 当前(2017年11月)节点和浏览器不支持对象散布运算符,因此您可以使用
Object.assign
语法
module.exports = [
Object.assign({}, { url: "https://blah.io/" }, genDateWithStatus("11/06/2017", "12/06/2017")),
];
or add the babel-plugin-transform-object-rest-spread transform plugin explicitly. 或显式添加babel-plugin-transform-object-rest-spread转换插件。
On the latter, see also Github issue: https://github.com/babel/babel-preset-env/issues/49 . 关于后者,另请参见Github问题: https : //github.com/babel/babel-preset-env/issues/49 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.