Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use module-alias in a library and NOT require it in the upper project (both Jest and runtime)? #118

Open
jnardone opened this issue Apr 23, 2021 · 1 comment

Comments

@jnardone
Copy link

I want to use aliases in an NPM package. Everything locally works - I register my aliases in code (and not package.json), all is well.

However, then I want to include this library in another project (or publish the library).

I want this other project, which may know nothing about module-alias, to be able to consume my library, both at runtime and using Jest. The parent project should NOT have to know anything about module-alias or the Jest resolver.

Is there any way to use module-alias in this way? Can I use aliases in a package and keep consumers of the package from having to know about how to deal with my library aliases?

@Kehrlann
Copy link
Collaborator

Hey @jnardone !

When working in a library, registering your aliases in code is the way to go, see Using within another NPM package.
However I would heavily recommend not exposing those aliases in your public API.

In any case, it will likely not work with Jest, since Jest overrides the default "require" behavior, see Usage with Jest.

Maybe you could look into "bundling" your lib into a single file before distributing it as a lib?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants