7

As I understand it from the npm docs, npm i /path/to/mylib should normally create a symlink of node_modules/mylib-> /path/to/mylib. However when I run that npm i command above, npm will not create symlinks but actually create a copy of the package in node_modules. Despite that my package.json will read "mylib" : "file:/path/to/mylib".

I want it to be a symlink since I am still working on the libraries I am adding in this project.

How can I make these symlinks?

  • node version 16.15.0
  • npm version 9.1.1
0

2 Answers 2

10

The change

This was a breaking change with npm v9. The release notes are available here.

Including this detail on the option;

install-links config defaults to "true"

In particular, there is this note in the release of node v18.4 here, motivating the change;

Explanation: install-links is the only config or command in the list that has an effect on package installs. We fixed a number of issues that came up during prereleases with this change. It will also only be applied to new package trees created without a package-lock.json file. Any install with an existing lock file will not be changed.

In our use case, this broke the build and a change to the intended use of the functionality to begin with.

If set to false, then the "current/old/pre v9" behaviour is restored.

Restoring the behaviour

Depending on the use case, there seem to be two options to consider;

  • Add the option --install-links=false to the command line. Good for single use cases.
  • Add the line install-links=false to the .npmrc file in the project root. Seems to be the better option for CI/CD environments.

Note: the package-lock file format may have to be version 3 (or above) for the above to work.

Sign up to request clarification or add additional context in comments.

1 Comment

2

I believe that your use case you should probably just use npm link.

If you're working on an application and one of its dependencies at the same time, you can use npm link to share the dependencies' project code inside your consuming application project.

It's a two step process:

  1. cd into dependency folder (eg ~/code/calculation-sdk) and run npm link
  2. cd into your main folder (eg ~/code/payment-service) and run npm link calculation-sdk

This will keep your code linked in both AND you still have the benefits of a clean npm based process.

If you want to clean everything up (eg delete the link), simply npm uninstall as you normally would.

Here's a nice article.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.