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 |2 Answers
Reset to default 12Your 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).
'lodash/cloneDeep'
– Diego Ortiz Commented Sep 6, 2019 at 15:23