-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
importModuleSpecifierPreference: "non-relative"
should use self-name package imports
#59620
Comments
Iβve never seen a project that exclusively uses self-name imports, and this is the first request for it Iβve heard in the years that weβve supported package.json |
I'm afraid I don't. We never had this problem when we used |
We do use relative imports in some cases where it makes sense. For example, if we have a package containing React components, the public exports would be the components, but each component module may use relative imports for private things e.g. to import a sibling CSS or a co-located helper module. This is why I suggested the following:
|
importModuleSpecifierPreference: "non-relative"
should use self-name package imports
π Search Terms
π Version & Regression Information
β― Playground Link
No response
π» Code
Full reduced test case: https://github.com/OliverJAsh/typescript-auto-imports-exports
Contents inlined below. TLDR:
packages/a
andpackages/b
.packages/b
depends onpackages/a
.Root files:
tsconfig.json
:package.json
:Package
a
:packages/a/package.json
:packages/a/module.ts
:packages/a/other-module.ts
:Package
b
:packages/b/package.json
:packages/b/module.ts
:π Actual behavior
packages/b/other-module.ts
uses the subpath export defined inpackages/a/package.json
. The suggested import path isa/test
. βpackages/a/other-module.ts
does not use the subpath export defined inpackages/a/package.json
. Instead it uses a relative import. The suggested import path is./module
.It seems that TypeScript is not using the subpath export information for self-referencing imports.
π Expected behavior
In both cases I would expect the subpath export to be used (rather than relative imports), otherwise you can end up with some verbose relative paths in the case of projects with deeply nested folders.
I would expect TypeScript to only use a relative import if a subpath export is not available.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: