无法在字符串 'and_chr 89' 上创建 属性 'and_ff'”
Cannot create property 'and_ff' on string 'and_chr 89'"
使用 Lambda 函数时遇到问题,收到错误,但如果我 运行 在 Express 应用程序中使用相同的代码,我不会收到相同的错误。我不是
Data returned by caniuse.getLatestStableBrowsers();
[
'and_chr 89', 'and_ff 86',
'and_qq 10.4', 'and_uc 12.12',
'android 89', 'baidu 7.12',
'bb 10', 'chrome 89',
'edge 89', 'firefox 87',
'ie 11', 'ie_mob 11',
'ios_saf 14.0-14.5', 'kaios 2.5',
'op_mini all', 'op_mob 62',
'opera 73', 'safari 14',
'samsung 13.0'
]
我遇到问题的 Lamda 代码
'use strict';
const caniuse = require('caniuse-api');
const request = require('request');
const browsers = caniuse.getLatestStableBrowsers();
const versions = browsers.reduce((memo, bro) => {
const parts = bro.split(' ');
memo[parts[0]] = parts[1];
return memo;
});
console.log(versions);
Express 代码运行良好
'use strict'
const express = require('express');
const caniuse = require('caniuse-api');
const app = express();
app.use(express.json());
app.get('/', (req, res) => {
const browsers = caniuse.getLatestStableBrowsers();
const versions = browsers.reduce((memo, bro) => {
const parts = bro.split(' ');
memo[parts[0]] = parts[1];
return memo;
}, {});
res.send({ versions });
});
array reducer 方法缺少初始值,而在 express 代码中定义了初始值。
'use strict';
const caniuse = require('caniuse-api');
const request = require('request');
const browsers = caniuse.getLatestStableBrowsers();
const versions = browsers.reduce((memo, bro) => {
const [browser, version] = bro.split(' ');
memo[browser] = version;
return memo;
}, {});
console.log(versions);
使用 Lambda 函数时遇到问题,收到错误,但如果我 运行 在 Express 应用程序中使用相同的代码,我不会收到相同的错误。我不是
Data returned by caniuse.getLatestStableBrowsers();
[
'and_chr 89', 'and_ff 86',
'and_qq 10.4', 'and_uc 12.12',
'android 89', 'baidu 7.12',
'bb 10', 'chrome 89',
'edge 89', 'firefox 87',
'ie 11', 'ie_mob 11',
'ios_saf 14.0-14.5', 'kaios 2.5',
'op_mini all', 'op_mob 62',
'opera 73', 'safari 14',
'samsung 13.0'
]
我遇到问题的 Lamda 代码
'use strict';
const caniuse = require('caniuse-api');
const request = require('request');
const browsers = caniuse.getLatestStableBrowsers();
const versions = browsers.reduce((memo, bro) => {
const parts = bro.split(' ');
memo[parts[0]] = parts[1];
return memo;
});
console.log(versions);
Express 代码运行良好
'use strict'
const express = require('express');
const caniuse = require('caniuse-api');
const app = express();
app.use(express.json());
app.get('/', (req, res) => {
const browsers = caniuse.getLatestStableBrowsers();
const versions = browsers.reduce((memo, bro) => {
const parts = bro.split(' ');
memo[parts[0]] = parts[1];
return memo;
}, {});
res.send({ versions });
});
array reducer 方法缺少初始值,而在 express 代码中定义了初始值。
'use strict';
const caniuse = require('caniuse-api');
const request = require('request');
const browsers = caniuse.getLatestStableBrowsers();
const versions = browsers.reduce((memo, bro) => {
const [browser, version] = bro.split(' ');
memo[browser] = version;
return memo;
}, {});
console.log(versions);