npm install without symlinks option not working
Asked Answered
J

4

37

I setup a development environment with Windows 8 and Ubuntu as a virtual machine. For that I use VirtualBox.

I also manage to create a shared folder in VirtualBox.

In this shared folder I try to start a project with ember-generator of Yeoman.

yo ember --skip-install --karma
npm install --no-bin-links

For installing modules NPM I use the option "--no-bin-links" not to create symbolic links. Unfortunately, I still have errors creations symbolic links ... Is what I use although this option ? There he has a bug ?

Jerky answered 29/1, 2014 at 8:42 Comment(5)
are you running npm from windows command prompt or from a bash prompt?Beaird
To me sounds like a bug report rather than a question.Deadradeadweight
@Bastien have you had any further progress on this?Boehmite
No, I changed my solution. I don't use shared folder.Jerky
Have a look on npmjs.com/package/install-localCamaraderie
N
58

The NPM docs about parameter "--no-bin-links" say:

will prevent npm from creating symlinks for any binaries the package might contain.

Which will just cause NPM to not create links in the node_modules/.bin folder. I also searched for a way to prevent NPM from creating symlinks when using npm install ../myPackage, but can't find any solution...

Update: The npm support team said this will reproduce the old behaviour (no symbolic links):

npm install $(npm pack <folder> | tail -1)

Works for me in git-bash on Windows 10.

Naomanaomi answered 10/7, 2017 at 15:47 Comment(4)
Any idea how the above could be accomplished in a package.json file?Earlap
@Vishal, see my solution to do remove symlinks after a build from package.json: https://mcmap.net/q/414270/-npm-install-without-symlinks-option-not-workingSecretarial
Or simply this command in powershell npm install (npm pack <folder>)Cuspidor
When NPM attempts to install the compiled package, I get the following: Cannot convert undefined or null to object.Raw
S
21

This Stack Overflow page comes up in Google search results when trying to solve the issue of installing local modules (ie. npm install ../myPackage) and not wanting symbolic links. So I'm adding this answer below to help others who end up here.

Solution #1 - For development environment.

Using the solution proposed by the NPM support team as mentioned in the other answer works...

# Reproduces the old behavior of hard copies and not symlinks
npm install $(npm pack <folder> | tail -1)

This is fine in the development environment for manual installs.

Solution #2 - For build environment.

However, in our case, the development environment doesn't quite matter as much though because when committing our changes to Git, the ./node_modules/ folder is ignored anyway.

The files ./package.json and ./package-lock.json is what is important and is carried into our build environment.

In our build environment (part of our automated CI/CD pipeline), the automation just runs the npm install command and builds from the dependencies listed in the package.json file.

So, here is where the problem affects us. The locally referenced files in the dependencies list of the package.json causes symlinks to appear. Now we are back to the old problem. These symlinks then get carried into the build's output which move onto the Stage and Production environments.

What we did instead is use rsync in archive mode with the --copy-links option that turns symbolic links into copies of the original.

Here is what the command looks like in the automated build:

# Install dependencies based on ./package.json
npm install

# Make a copy that changes symlinks to hard copies
rsync --archive --verbose --copy-links ./node_modules/ ./node_modules_cp/

# Remove and replace
rm -r ./node_modules/
mv ./node_modules_cp/ ./node_modules/
Secretarial answered 8/2, 2019 at 8:16 Comment(3)
How to use the first solution ? What is the <folder> ?Annadiane
<folder> is the local package folderSoave
I have tried all of these to no avail. Mac Monterey. I have a Git submodule with node_module code in it and I require it via a file link in the package.json like this "cchome-shared": "file:./local_modules/cchome-shared-server", and I have yet to get it to not be a symlink.Earth
D
3

I have a similar environment. Apparently the Virtualbox (vagrant) synchronisation has problems when renaming or moving files, which happens when updating modules.

If you do a file listing (ls -alhp) on the command line and see ??? for the file permissions, then it is time to reboot your virtualbox. This will set the permissions to valid values. Then use the --no-bin-links option when installing a module.

Devest answered 8/6, 2014 at 21:19 Comment(0)
I
2

npm install <folder> --install-links will install a package from a local folder by copying it rather than symlinking it, and npm install --install-links will do the same for packages in the package.json.

I don't believe there's a way you can specify in the package.json alone (ie: without command-line switches on the install command) that you want this behaviour. For that you probably need to point the package.json at a package tarball on the local filesystem rather than a package folder.

Incorruption answered 19/6, 2023 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.