import has from 'lodash/has'; is better because lodash holds all its functions in a single file, so rather than import the whole 'lodash' library at 100k, it's better to just import lodash's has function which is maybe 2k.
» npm install lodash-es
Correct way to import lodash
What is the final way to import es lodash modules?
Merge lodash-es into lodash package
ts node - How to use lodash-es in typescript correctly? - Stack Overflow
import has from 'lodash/has'; is better because lodash holds all its functions in a single file, so rather than import the whole 'lodash' library at 100k, it's better to just import lodash's has function which is maybe 2k.
If you are using webpack 4, the following code is tree shakable.
import { has } from 'lodash-es';
The points to note;
CommonJS modules are not tree shakable so you should definitely use
lodash-es, which is the Lodash library exported as ES Modules, rather thanlodash(CommonJS).lodash-es's package.json contains"sideEffects": false, which notifies webpack 4 that all the files inside the package are side effect free (see https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free).This information is crucial for tree shaking since module bundlers do not tree shake files which possibly contain side effects even if their exported members are not used in anywhere.
Edit
As of version 1.9.0, Parcel also supports "sideEffects": false, threrefore import { has } from 'lodash-es'; is also tree shakable with Parcel.
It also supports tree shaking CommonJS modules, though it is likely tree shaking of ES Modules is more efficient than CommonJS according to my experiment.
You can load types from here:
npm install --save-dev @types/lodash-es
And use it like:
import { camelCase } from "lodash-es"
ts-node compiles .ts files as they are loaded. It doesn't touch .js files; either they must already be in a form understood by Node.js (e.g., no ES6 import statements) or you must use a separate mechanism to transform them, such as the @babel/register require hook (essentially the same thing that is used by babel-node). You would still need to configure @babel/register not to ignore node_modules, as described in the other answer. The advice from the other answer to just use lodash instead of lodash-es is good.
In addition to installing the @types/lodash-es module, the existing "lodash": "^4.17.15" module needs to be replaced with "lodash-es": "^4.17.15"
This is because @types/lodash-es requires lodash-es and not lodash. This is obvious once you know it but I missed it originally.
Try this
npm install @types/lodash-es --save-dev
If after this you will have the same problem please check the package.json that you have in dependencies
"lodash-es": "^4.17.20"
when you dont have, just write and run npm install in cmd . This work for me.
» npm install @types/lodash-es