Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update npm package from a local folder

I cloned some npm package from github and put the package in a local folder, e.g.

c:\git\package

I used "npm install -g" to install the package, which works really well.

npm install -g c:\git\package

However, when I did some change in the code of the package, e.g. checked out some branch. I couldn't use "npm update" to update the installed package. I have tried:

npm update -g

and

npm update -g packagename

or

npm update -g folderpath

Neither worked. I have to use "npm install" to reinstall it again for updating, which is wasting time to reinstall all dependencies.

Why does npm only support install from folder but not update from folder? If it does support, what shall I do? Thanks.

like image 695
bigbearzhu Avatar asked Jun 19 '13 21:06

bigbearzhu


People also ask

How do I update my npm packages?

Use npm outdated to list the packages that are out of date with respect to what is installed in package.json Use npm update package_name to update an individual package that has already been installed. Use npm uninstall package_name and npm install package_name@version to revert to a specific version.

What does NPM Install <folder> do?

Since npm install <folder> adds the package in the directory as a symlink in the current project any changes to the local package are automatically synced. Anjum....

What happens if there is no package name in NPM?

If no package name is specified, all packages in the specified location (global or local) will be updated. As of [email protected], the npm update will only inspect top-level packages. Prior versions of npm would also recursively inspect all dependencies. To get the old behavior, use npm --depth 9999 update.

How do I know if NPM install works correctly?

Since private packages are always scoped, you must reference the scope name during installation: To confirm that npm install worked correctly, in your module directory, check that a node_modules directory exists and that it contains a directory for the package (s) you installed:


1 Answers

Instead of npm install from a local directory, try npm link, which creates a globally-installed symlink to the directory.

As stated in the docs, this is a two-step process:

  1. In package directory:

    $ npm link
    

    This creates a symlink to the current folder in npm's global installation directory.

  2. Somewhere else, where you want to use the module:

    $ npm link <pkgname>
    

    This will create a symlink in your project's node_modules/ folder to the global installation.

like image 158
jches Avatar answered Oct 16 '22 01:10

jches