Peer dependency that is also dev dependency of linked npm module is acting as a separate instance


(IRCraziestTaxi) #1

I asked this question on StackOverflow, but it’s not getting any attention and I need some guidance on this. Pasting the question here.

In my app, I have these dependencies:

TypeORM

typeorm-linq-repository AS A LOCAL INSTALL ( "typeorm-linq-repository": "file:../../../IRCraziestTaxi/typeorm-linq-repository" ), who has a dev dependency AND a peer dependency of TypeORM

The reason I use a "file:" installation of typeorm-linq-repository is that I am the developer and test changes in this app prior to pushing releases to npm.

I was previously using node ~6.10 (npm ~4), so when I used the "file:" installation, it just copied the published files over, which is what I want.

However, after upgrading to node 8.11.3 (npm 5.6.0), it now links the folder rather than copying the published files.

Note, if it matters, that my environment is Windows.

The problem is this: since both my app and the linked typeorm-linq-repository have TypeORM in their own node_modules folders, TypeORM is being treated as a separate “instance” of the module in each app.

Therefore, after creating a connection in the main app, when the code that accesses the connection in typeorm-linq-repository is reached, it throws an error of Connection "default" was not found. .

I have searched tirelessly for a solution to this. I have tried --preserve-symlinks , but that does not work.

The only way for me to make this work right now is to manually create the folder in my app’s node_modules and copy applicable files over, which is a huge pain.

How can I either tell npm to NOT symlink the "file:" installation or get it to use the same instance of the TypeORM module?


(IRCraziestTaxi) #2

I made it work pretty easily, although I feel like it’s kind of a band-aid. I will post the answer here to help anybody else who may be having this issue, but if anybody has a more proper solution, feel free to answer and I will accept.

The trick was to link my app’s installation of TypeORM to the TypeORM folder in my other linked dependency’s node_modules folder.

...,
"typeorm": "file:../../../IRCraziestTaxi/typeorm-linq-repository/node_modules/typeorm",
"typeorm-linq-repository": "file:../../../IRCraziestTaxi/typeorm-linq-repository",
...

(system) #3

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.