How to force npm not to create symbolic link to local package?
Asked Answered
B

2

2

I downloaded local copy of npm package and extracted it on desktop. Then I used npm install /directory/ to install it.

What I noticed is that when I remove desktop directory, app says it can't find installed module. After further investigation I noticed that package is in node_modules but it has arrow next to it and it says "symbolic link" which I suppose is a link to desktop directory with this package.

How do I install it independently so that it is fully contained in node_modules allowing me to remove desktop copy?

Blubberhead answered 8/11, 2021 at 10:41 Comment(5)
How did you download the "local copy"? Is it something not on the online repository?Klusek
It is a paid javascript library and it's not hosted on any site. You get direct download link to it. It is an npm package though. It has package.lock file in it, javascript code and ts type definitions.Blubberhead
Do they have documentation on how to install it (probably in their README or somewhere), then?Klusek
Okay you get your answer here. #8089295Klusek
This doesn't resolve my issue. I resolved it other way and posted below.Blubberhead
B
9

Turns out you can use

npm pack /path/to/package

This will cause npm to pack package into a .tgz file. Then you can install it from a .tgz file using a standard

npm install /path/to/file.tgz

This will force npm to create a local copy in node_modules without symbolic link

Blubberhead answered 8/11, 2021 at 10:54 Comment(0)
G
0

To build on the excellent answer from ablaszkewicz1, the solution is to use npm pack to create a tarball and then npm install the tarball. However the name of the tarball varies depending on whether the package is namespaced, so it is a bit tricky to just put this in a shell alias.

So here is a convenient bash script to do this any time you need it:

#!/bin/bash

mkdir -p /tmp/$$ &&
npm pack --pack-destination=/tmp/$$ $1 &&
NAME=`ls /tmp/$$/*tgz` &&
npm install $NAME &&
rm -rf /tmp/$$

Usage:

try ../apostrophe

That will install the module in the adjacent folder ../apostrophe in the current project folder.

Githens answered 13/4 at 16:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.