Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM: After "npm link" module is not found

Tags:

node.js

npm

People also ask

Why npm link is not working?

To fix this, use node -v in each project and check the running version of node. Use nvm install x.x.x & nvm use x.x.x to match them up. Afterward, delete your node_modules , delete your package-lock. json , re-run npm i , and re-run npm link in your dependency folder and npm link myDependency in your project folder.

How do I link npm modules?

Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.

How do I find npm links?

You can find the path to your global node_modules directory by running npm root -g . When you run npm link <module_name> in a project's directory, npm creates a symbolic link from ./node_modules/<module_name> to <global_node_modules>/<module_name> . That's it: no magic, just symbolic links.

What is npm link command?

Description. Package linking is a two-step process. First, npm link in a package folder will create a symlink in the global folder {prefix}/lib/node_modules/<package> that links to the package where the npm link command was executed. It will also link any bins in the package to {prefix}/bin/{name} .


The problem was that the main property of package.json was pointing to a non-existing file. It seems that the problem can happen due to multiple reasons so be sure to take a look at other answers.


I ran into this issue because of NVM, I was running one version of node for the dependency and another for the dependant.


Deleting package-lock.json then running npm install again resolved the issue for me.


When you first run npm link from the aligator directory, you create a link from your global node_modules directory to aligator. Then when you run the npm link aligator from the aligator-methods directory, you link aligator from your locally installed node_modules to the original source (as the output shows in your example above). Once this is done, there shouldn't be a need to install anymore since it's already "installed". What errors are you seeing after you run the npm link aligator command?

If you just want to install a dependency from a local directory, you might just try using npm install instead. For example:

$ cd ~/aligator-methods
$ npm install ../aligator


My issue ended up being that repo A was using npm and repo B was using yarn, so I needed to run yarn link in repo B in order to pull it in via npm link package-name into repo A.