我收到错误,因为“异步函数”仅在 es8 中可用(使用“esversion 8”)” 我尝试在内联代码 package.json 中放入“esversion:8”,但它不起作用,并且函数未部署。
代码: index.js
'use strict';
'use esversion: 8'; //not working
async function getWeather() {
const city = 'Mumbai';
const OPENWEATHER_API_KEY = '<API KEY>';
const response = await fetch(`http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${OPENWEATHER_API_KEY}`);
const data = await response.json();
console.log(data);
const { main } = data;
const { temp } = main;
const kelvin = temp;
const celsius = Math.round(kelvin - 273.15);
console.log(celsius);
}
Run Code Online (Sandbox Code Playgroud)
代码package.json
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a …Run Code Online (Sandbox Code Playgroud) javascript node.js google-cloud-functions dialogflow-es dialogflow-es-fulfillment