Yuri Gor
Yuri Gor

Reputation: 1463

Is lodash built into Node?

This works without lodash installed as dependency:

const _ = require('lodash');
_.each([1,2,3],console.log);

(no, I have no lodash installed globally)

I saw somewhere something like nodejs supports lodash by default, but now I cannot find any documentation about this. Is it finally true? Where can I read about it?

P.S. Finally I found and deleted node_modules in my home directory, and all the magic gone, now this script produces an error for missing dependency. Thank you guys for help in this investigation.

Upvotes: 4

Views: 4185

Answers (3)

Chris
Chris

Reputation: 58142

I think Akrion is partially correct in what he is saying (not needing lodash anymore, lodash not being part of node by default).

My guess as to why its working, is that you have a required library that in turn has a dependency on lodash and whatever bundler you are using is picking it out that way.

I would hazard a guess here to say that if you open your node_modules folder lodash is sitting there. Take a squizz through your package.lock file (or yarn lock file) and see what is including lodash.

EDIT As discovered through the comments, there was a node_modules folder in a home directory

Upvotes: 4

Akrion
Akrion

Reputation: 18515

Not really. It does not make much sense to bundle out of the box 100K+ lib and assume that it would be used by the developer. For example consider this Repl example

It would do a node environment and would install any packages specified in the require statements. If none are provided it is just a plain node with nothing else.

As you can see out of the box you would get _ is not defined. but the moment you add the const _ = require('lodash') it would auto-install the lodash for you and you will get the desired result. So this is done by Repl tool for convenience so you do not have to do npm install ... etc. But out of the box node is not packaged with lodash.

Also with ES6 good amount of the lodash use cases are not there anymore and once ES6 becomes widely supported the argument about browser compatibility of lodash would also not matter as much. So going forward would make even less sense to bundle it with node.

What is interesting however is that the npm included as deps in node repo has dependencies on lodash :).

Upvotes: 5

dsalcovs
dsalcovs

Reputation: 41

The library is not built into node. You can look at the full list of built in modules @

https://github.com/nodejs/node/tree/master/lib

Upvotes: 3

Related Questions