40
votes

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.

2
Thanks a bunch @HardikModha :)l-lin
I tried using install-local, but it also creates symlinks so @HardikModha's solution doesn't work 100%. It also has the undesirable side effect of not installing the dependencies of the local dependencies.Severun

2 Answers

34
votes

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.

0
votes

I wrote npm-install-offline which allows you to install npm packages from a local repository or folder. By default it copies the folder on install but you can also choose to symlink. https://www.npmjs.com/package/npm-install-offline

npx npm-install-offline ../some-package

Or

npx npm-install-offline my-npm-package --repo ./my-offline-npm

It also will install the package dependencies which npm does not do with local packages.