Closed jepetko closed 4 years ago
This issue is related to the way how npm
resolves the modules. In this case, decorators placed in the lib (for B
and A
) are referring stuff from some-lib\node_modules\typescript-ioc
. However, some-app
is using node_modules\typescript-ioc
. Those two DI containers don't know anything about each other and thus A
cannot be injected into B
.
One possible solution for a reasonable local development would be to use some-lib
linked, however, without node_modules installed. Then, --preserve-symlinks
would use the local typescript-ioc
dependency. The caveat is that modules must not be installed in some-lib
.
Any better ideas?
So here are the options:
Option A:
some-lib
: put typescript-ioc
as devDependency (and ambientDependency)some-lib
with npm link --only=production
the drawback is that node_modules
must not contained development dependencies which is not feasible as you need devDependencies for further development of the library.
Option B:
provide a script which does the following:
"my-link": "mv node_modules node_modules_backup && npm link",
"my-unlink": "npm unlink && mv node_modules_backup node_modules"
DI does not work for libraries which are linked locally via
npm link some-lib
.classes provided by
some-lib
:@Singleton export class A { constructor() { console.info('A created'); }
}
usage in
some-app
whereas the library is used as a linked library (npm link some-lib
):IMPORTANT: note that the behavior is the same no matter whether the alias is used or not (also see https://github.com/jepetko/some-app/commit/d658f49542100b009ffd5aeae13c332a63958dc6#diff-aaae91aceb351151eeeb6a1e04817a9c which does not contain any alias)
Expected result for
npm start
(works when the lib is installed vianpm i
or copied intonode_modules
):Actual result for
npm start
(does not work when the lib is installed vianpm link some-lib
):Sources