36

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 ?

5
  • are you running npm from windows command prompt or from a bash prompt? Mar 17, 2014 at 2:13
  • To me sounds like a bug report rather than a question. Mar 22, 2014 at 16:22
  • @Bastien have you had any further progress on this? Apr 24, 2014 at 9:55
  • No, I changed my solution. I don't use shared folder.
    – Bastien D
    Apr 30, 2014 at 8:13
  • Have a look on npmjs.com/package/install-local
    – vitalets
    Oct 19, 2017 at 16:23

4 Answers 4

55

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.

4
  • 7
    Any idea how the above could be accomplished in a package.json file?
    – Vishal
    May 15, 2018 at 10:14
  • @Vishal, see my solution to do remove symlinks after a build from package.json: stackoverflow.com/a/54588310/2598101 Feb 8, 2019 at 8:17
  • Or simply this command in powershell npm install (npm pack <folder>)
    – Jeruntu
    Nov 26, 2020 at 12:23
  • When NPM attempts to install the compiled package, I get the following: Cannot convert undefined or null to object. Oct 3, 2021 at 18:55
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/
3
  • 3
    How to use the first solution ? What is the <folder> ?
    – Loenix
    Jan 7, 2020 at 16:12
  • 1
    <folder> is the local package folder
    – isick
    Mar 4, 2021 at 20:04
  • 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.
    – gnichola
    May 19, 2022 at 17:20
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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.