Where is lodash.js after install via npm? - javascript

I ran npm insall lodash but I can't find the lodash.js file to include in the browser. I realize I can just download lodash.js but I would prefer to use npm if possible.

Newer versions of lodash packages replace lodash.js with index.js. Use node_modules/lodash/index.js.

npm installs all of the modules in to the node_modules folder. So you'd find lodash in ./node_modules/lodash/
If you're using browserify, you don't need to worry about that location as you can simply var _ = require('lodash'); and browserify will take care of the files for you.
More info on Browserify at: http://browserify.org/

Related

Can I use in my project a package from package-lock.json dependencies?

I want to use date-fns in my project and I already have react-datepicker which is using date-fns. So, is it possible to use date-fns from react-datepicker or is it necessary to install it separately to the project in order to use it?
Yes, it is possible to use modules which are installed as dependencies to other modules directly, most of the time with no issues.
But to be on the safer side install those modules and make it available in your package.json. Anyhow, only one folder of each module will be present even if you install it multiple times!
Proof: Dependencies of other modules reside in root of node_modules folder and not inside the installed module.

Webpack seems to be including node_modules of node_modules into bundle?

So I have recently discovered that webpack seems to be including node_modules dependencies inside my top level node_modules dir into my actual bundle. For example, one dependency, example-dep depends on lodash, and so has a node_modules dir inside node_modules/example-dep, with lodash inside. Because example-dep imports one method from lodash, for some reason the entire lodash library is getting thrown into my bundle.
How can I fix this? Why are there nested node_module dirs inside my dependencies anyways? It's not like I am building those projects and trying to contribute to them, I literally just do npm install example-dir.
Those node_modules directories are installed because are listed as devDependencies of the package (in case you want to build yourself or test). To install solely the built file
npm install --production <package>
or better
npm install --only=prod
For more details check https://docs.npmjs.com/cli/install.

Check which npm package installs lodash dependency

I am using webpack to build a production bundle for an application, and lodash, although I have not explicitly installed it and it does not exist in my package.json, is being inserted in my node_modules folder.
When I run npm uninstall --save-dev lodash (which effectively removes the lodash folder from node_modules), and rerun the build process, my bundle shrinks significantly. I would like to determine which package includes and requires the full lodash library.
How can I determine which of my many npm packages are requiring lodash?
Note:
I am using the packages lodash.debounce and lodash.throttle. But lodash.throttle only has a dependency of lodash.debounce and lodash.debounce does not have any other lodash dependencies.
I was looking for typescript package which is upgrading from 3.5.3 to 3.9.7 implicitly.
With the help of #Kenan I will make contribution:
When run as ll or la, it shows extended information by default.
Blockquote
https://docs.npmjs.com/cli/ls.html
npm [ls|la|list] [[<#scope>/]<pkg> ...]
In my situation typescript version ^3.5.3 in package.json but it was upgrading to 3.9.7 because of ^ character. npm is intalling this package's latest version of major version 3. Installed version 3.9.7 doesn't match in any typescript dependency in package.json files.

how to use jquery file upload with ember browserify

I'm trying to use jquery file upload with ember-cli using the npm package
https://www.npmjs.com/package/blueimp-file-upload
and ember browserify.
I installed ember-browserify and blueimp-file-upload:
$ npm install --save-dev ember-browserify
$ npm install --save-dev blueimp-file-upload
Importing fileupload like so:
import fileupload from 'npm:blueimp-file-upload';
Gave me this error:
Cannot find module 'jquery' from '/Users/tony/src/myapp/node_modules/blueimp-file-upload/js/vendor’
So I installed jquery via npm as well:
$ npm install --save-dev jquery
Now I just get this error when trying to use fileupload:
$(...).fileupload is not a function
Is there a better way to use jquery-fileupload with ember-cli?
First, there is a few plugins for ember that provide you with a ready-to-use solution. If I remember right, one of them utilizes blueimp file upload. You may use one of them or look how they use underlying jquery plugins.
You may also try to install jquery-ui-widget and blueimp-file-upload via bower.
And finally, you may write your own file uploader without using 3rd-party jquery plugins.

How do I use lodash, and JS modules in general

I just installed Node and I want to use the lodash library. I made a new JS file in my desktop and I started the file with
var _ = require('lodash');
However, I get
Error: Cannot find module 'lodash'
How do I use the lodash library? All I can find online says to use the import statement I already used.
You need to install lodash with npm:
npm install lodash
That will install lodash into a subdirectory of your current directory called node_modules. Node.js knows to look there when you use require('lodash').
Usually you'll have a package.json file that tracks your dependencies so that you can just do npm install to install all dependencies for a project. If you want to add lodash to package.json then you can use npm install --save lodash.
If you don't have a package.json for your project yet, I would recommend running npm init to create one.

Categories

Resources