Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm 5 install folder without using symlink

Tags:

npm

Before publishing my node library, I could use the advice the npm documentation wrote about:

To test a local install, go into some other folder, and then do:

cd ../some-other-folder

npm install ../my-package

Prior to version 5 of npm, I had no problem as it produce what I expected, ie a folder with the output of what I will publish.

However, using npm 5, it now creates a symlink to my local project as described in the npm documentation:

npm install :

Install the package in the directory as a symlink in the current project. Its dependencies will be installed before it's linked. If sits inside the root of your project, its dependencies may be hoisted to the toplevel node_modules as they would for other types of dependencies.

How can I use the "old" way to install local project? Or is there a new way to check if my library is correct?

Thank you.

like image 555
l-lin Avatar asked Jun 19 '17 07:06

l-lin


People also ask

How do I use NPM link in a package folder?

First, npm link in a package folder will create a symlink in the global folder {prefix}/lib/node_modules/ that links to the package where the npm link command was executed. It will also link any bins in the package to {prefix}/bin/ {name}. Note that npm link uses the global prefix (see npm prefix-g for its value).

What is a symlink in NPM?

A symlink, short for symbolic link, is a shortcut that points to another directory or file on your system. Tell the application to use the global symlink with npm link some-dep.

What is the difference between NPM install--link and--no bin-links?

npm install (in package directory, no arguments): Install the dependencies in the local node_modules folder. ... The --link argument will cause npm to link global installs into the local space in some cases. The --no-bin-links argument will prevent npm from creating symlinks for any binaries the package might contain.

What does NPM install-p mean?

`npm install` saves any specified packages into `dependencies` by default. * `-P, --save-prod`: Package will appear in your `dependencies`. This is the default unless `-D` or `-O` are present.


1 Answers

Use npm pack + npm install (as suggested by install-local package)

npm pack <path-to-local-package> npm install <package-version.tgz> 

This will effectively copy your local package to node_modules. Note that this will package only production relevant files (those listed in the files section of your package.json). So, you can install it in a test app under the package own directory. Something like this:

my-package   package.json   test     test-app       package.json       node_modules         my-package 

Assuming that test dir is not included in the files in my-package/package.json.

This works the same way with npm 5 and older versions.

like image 50
Peter Dotchev Avatar answered Oct 01 '22 01:10

Peter Dotchev