npm install without symlinks option not working

27,897

Solution 1

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.

Solution 2

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/

Solution 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.

Share:
27,897
Bastien D
Author by

Bastien D

Web developer at Bordeaux in France

Updated on August 27, 2020

Comments

  • Bastien D
    Bastien D over 3 years

    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 ?