Source:  Twitter logo

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.

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);
9 users liked answer #0dislike answer #09
agascon profile pic
agascon

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).

1 users liked answer #1dislike answer #11
Moslem Shahsavan profile pic
Moslem Shahsavan

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).