question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IMPORTANT: DO NOT USE! Use import mapping instead

See original GitHub issue

A similar feature to this library is already available in node as a standard: import mapping.

Not only does it allow for directory mapping, but it also allows dependency aliasing, and works for both require and import (ESM) WITHOUT breaking resolution behaviour in production or other libraries like using this library does.

You have been warned.

I know this sounds hateful, however, that is not my intention. My intention is instead to spread awareness about this mostly undocumented feature (it is not shown in any package manifest documentation besides node’s, and it is relatively tucked away) so people can write better software without needing to use hacky libraries like this one and without adding unnecessary dependencies.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:42
  • Comments:53 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
Nytelife26commented, Mar 9, 2021

@Papooch you will have to convert to using #alias instead of @alias, but that’s it.

"imports": {
    "#root/*": "./*",
    "#submodules/*": "./submodules/*",
    "#db/*": "./src/db/*",
    "#middleware/*": "./src/middleware/*"
}

I hope that helps.

6reactions
Kehrlanncommented, Feb 21, 2021

@Nytelife26 , thanks for raising awareness. This was introduced “recently”, so on older versions of node, you might still want module-alias - therefore we probably won’t just “deprecate” the package.

Would you mind opening a PR to update the README of this package, explaining that import mapping exists and should be used instead?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Everything You Need to Know About JavaScript Import Maps
Import maps are a new way for web pages to control the behavior of JavaScript imports, potentially enabling you to ditch your build...
Read more >
in VS Code ImportError: cannot import name 'Mapping' from ...
You can solve this problem with use python 3.9 or 3.8 version. or if error from packages like python-docx or other packages about...
Read more >
How to Dynamically Import JavaScript with Import Maps
The import map is a map of locations, and doesn't import any code itself. One major problem is that import maps are not...
Read more >
Using ES modules in browsers with import-maps
The below chart shows that all major browsers including Edge, Chrome, ... But if you did not use import-maps , you have to...
Read more >
Configuring the Style of Imports in JavaScript and TypeScript
The option “Do not import exactly from” allows you to tell the IDE that you don't want any imports that are from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found