node.js - 更新 lodash 版本到 4.17.4 破解代码
问题描述
我将 lodash 更新到4.17.4版本,Typescript 开始抛出这个错误:
TypeError: _.uniqBy is not a function Uncaught TypeError: _.split is
not a function
我的代码如下所示:
import * as _ from 'lodash';
const uniqueRecordType = _.uniqBy(rArr,'recordtype');
这个功能是否已从lodash中删除?
解决方案
根据文档,以下应该有效:
const uniqBy = require('lodash.uniqby');
const uniqueRecordType = uniqBy(rArr,'recordtype');
如何安装 lodash 依赖项:
npm install --save lodash.uniqby
当使用 ECMAScript 5 和 CommonJS 模块时,你可以像这样导入它:
var uniqBy = require('lodash.uniqby');
使用 ES6 模块,这将是:
import uniqBy from 'lodash.uniqBy';
推荐阅读
- anaconda - Spyder 5.0.3 仍然显示缺少依赖项
- linux - 我们如何检查我们的邮件服务以及如何阻止来自 linux 服务器的外发电子邮件
- blpapi - 如何使用 pip(不是 conda)下载 blpapi 3.13.1
- javascript - 限制 URL 末尾的正斜杠
- r - 函数 AUC 包 Desctools:如何延长曲线
- flutter - 如何在运行 --android-licenses 后更正此错误“错误:无法找到或加载主类”
- python - 为什么python中的递归函数会出现内存错误?
- javascript - 根据申请表中选择的id更改要填写的字段(活动表保存所选项目具有的活动字段)
- google-apps-script - 在谷歌表格中的 60 天滚动窗口中删除重复项
- mysql - RDBMS Resource Usage when Using PrestoDB