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

Support import maps and bare import specifiers #43326

Open
5 tasks done
bahrus opened this issue Mar 20, 2021 · 2 comments
Open
5 tasks done

Support import maps and bare import specifiers #43326

bahrus opened this issue Mar 20, 2021 · 2 comments
Assignees
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript

Comments

@bahrus
Copy link

bahrus commented Mar 20, 2021

Suggestion

πŸ” Search Terms

  1. import maps
  2. bare import specifiers

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

As import maps are part of Chrome (as of version 89), and Firefox has given a nod of approval, it would be great if Typescript embraced this cross-package import syntax.

Import maps assume an index.html (for example) file with a script tag, e.g.:

<script type="importmap">
{
  "imports": {
    "moment": "/node_modules/moment/src/moment.js",
    "lodash": "/node_modules/lodash-es/lodash.js"
  }
}
</script>

I would suggest being able to

  1. Point to a file containing such an importmap in tsconfig and/or
  2. Just supporting bare import specifiers, based on package.json/package-lock.json, the way unpkg.com is able to do..

πŸ“ƒ Motivating Example

Now you can reference cross-package JS files seamlessly, without bundling tools, based on browser standards.

Workaround:

The path resolution Typescript provides is inadequate, and quite unhelpful.

The only fairly reliable workaround I've found is cloning the repo to a sibling folder of my project.

@RyanCavanaugh RyanCavanaugh added Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript labels Mar 22, 2021
@matthew-dean
Copy link

matthew-dean commented Nov 22, 2022

I would love to see this implemented in Node.js, and then just automatically picked up by TypeScript as an alternative to paths.

Edit: Oh hang on, this blog post claims it is implemented in Node? https://blog.spencersnyder.io/solving-the-long-relative-paths-problem-natively-in-node-js-6aeebc3a81bd. Can TypeScript just pick this up the import key to resolve?

@CMCDragonkai
Copy link

It seems that at the moment one has to still specify paths mapping in tsconfig.json to get tsc to understand the #internal paths that now exists in package.json for NodeJS packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants