最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error using lodash.clonedeep in Angular 5 - Stack Overflow

programmeradmin1浏览0评论

First, I have never used lodash.clonedeep before but know JavaScript fairly well.

From my package,json file: "lodash.clonedeep": "4.5.0",

import { cloneDeep } from 'lodash.clonedeep';

editStart(): void {
   this.oldData = cloneDeep(this.currentData);
   this.editing = true;
}

Error: ERROR TypeError: lodash_clonedeep_1.cloneDeep is not a function

Help very MUCH appreciated since I'm out of options, have read and tried a lot of options. I have a workaround, using several objects, but want to avoid if possible.

First, I have never used lodash.clonedeep before but know JavaScript fairly well.

From my package,json file: "lodash.clonedeep": "4.5.0",

import { cloneDeep } from 'lodash.clonedeep';

editStart(): void {
   this.oldData = cloneDeep(this.currentData);
   this.editing = true;
}

Error: ERROR TypeError: lodash_clonedeep_1.cloneDeep is not a function

Help very MUCH appreciated since I'm out of options, have read and tried a lot of options. I have a workaround, using several objects, but want to avoid if possible.

Share Improve this question asked Feb 25, 2018 at 10:07 SveinSSveinS 2131 gold badge4 silver badges10 bronze badges 2
  • Can you show us your package.json?? – alt255 Commented Feb 25, 2018 at 12:13
  • Your sintax is ok, you only need to change the . for /, and use camelCase like this 'lodash/cloneDeep' – Diego Ortiz Commented Sep 6, 2019 at 15:23
Add a comment  | 

2 Answers 2

Reset to default 12

Your import statement is incorrect.

You should either import the full library:

import * as _ from 'lodash';
...
let foo = _.cloneDeep(bar);

Or import just the cloneDeep function:

import * as cloneDeep from 'lodash/cloneDeep';
...
let foo = cloneDeep(bar);

My experience on the Angular 7:

When use in src project:

import * as cloneDeep from "lodash/cloneDeep";

When use in library project:

import cloneDeep from "lodash/cloneDeep";

Note: Better import per-module to decrease main module size (the-correct-way-to-import-lodash-libraries-a-benchmark).

发布评论

评论列表(0)

  1. 暂无评论