NPM: After “npm link” module is not found

后端 未结 10 887
情深已故
情深已故 2021-02-11 11:31

I\'m developing two modules for NodeJS, first one named aligator and second one aligator-methods. Second one depends on first one to work. I\'m develop

相关标签:
10条回答
  • 2021-02-11 12:14

    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

    0 讨论(0)
  • 2021-02-11 12:14

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

    0 讨论(0)
  • 2021-02-11 12:16

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

    0 讨论(0)
  • 2021-02-11 12:17

    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.

    0 讨论(0)
  • 2021-02-11 12:18

    Check tsconfig moduleResolution

    If like me, you happened to change the tsconfig module from es5 to esnext or something, then the moduleResolution default may have changed.

    Without moduleResolution being set to "node", typescript will not resolve node_modules packages.

    You can read on the Compiler Options page about how the default value depends on the value of module, whose default in turn depends on target — but probably set it to "node" explicitly.

    0 讨论(0)
  • 2021-02-11 12:19

    For me this happened when I decreased the version number of my local package from 0.1.0 to 0.0.1. And in the projects where I linked to this package I was still using the higher version number. Updating dependencies in package.json fixed it.

    0 讨论(0)
提交回复
热议问题