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

chore(developer): remove 'paths' from tsconfig.json #12027

Closed
mcdurdin opened this issue Jul 25, 2024 · 0 comments · Fixed by #12028
Closed

chore(developer): remove 'paths' from tsconfig.json #12027

mcdurdin opened this issue Jul 25, 2024 · 0 comments · Fixed by #12028
Assignees
Milestone

Comments

@mcdurdin
Copy link
Member

mcdurdin commented Jul 25, 2024

Per https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths:

While it’s ok for bundled apps to set up paths, it’s very important that published libraries do not, since the emitted JavaScript will not work for consumers of the library without those users setting up the same aliases for both TypeScript and their bundler. Both libraries and apps can consider package.json "imports" as a standard replacement for convenience paths aliases.

paths should not point to monorepo packages or node_modules packages

While module specifiers that match paths aliases are bare specifiers, once the alias is resolved, module resolution proceeds on the resolved path as a relative path. Consequently, resolution features that happen for node_modules package lookups, including package.json "exports" field support, do not take effect when a paths alias is matched. This can lead to surprising behavior if paths is used to point to a node_modules package:

{
  "compilerOptions": {
    "paths": {
      "pkg": ["./node_modules/pkg/dist/index.d.ts"],
      "pkg/*": ["./node_modules/pkg/*"]
    }
  }
}

While this configuration may simulate some of the behavior of package resolution, it overrides any main, types, exports, and typesVersions the package’s package.json file defines, and imports from the package may fail at runtime.

The same caveat applies to packages referencing each other in a monorepo. Instead of using paths to make TypeScript artificially resolve "@my-scope/lib" to a sibling package, it’s best to use workspaces via npm, yarn, or pnpm to symlink your packages into node_modules, so both TypeScript and the runtime or bundler perform real node_modules package lookups. This is especially important if the monorepo packages will be published to npm—the packages will reference each other via node_modules package lookups once installed by users, and using workspaces allows you to test that behavior during local development.

It looks like this may be responsible for the build failure described in #10254.

@mcdurdin mcdurdin changed the title chore(developer): remove 'paths' from tsconfig.json chore(developer, common): remove 'paths' from tsconfig.json Jul 25, 2024
@mcdurdin mcdurdin changed the title chore(developer, common): remove 'paths' from tsconfig.json chore(developer): remove 'paths' from tsconfig.json Jul 25, 2024
mcdurdin added a commit that referenced this issue Jul 26, 2024
During analysis of root causes for #12027, discovered a few package
relationship issues in package.json and build.sh.

analyzer-messages.ts ///<reference> is a mitigation for now.

Relates-to: #12027
@mcdurdin mcdurdin linked a pull request Jul 26, 2024 that will close this issue
@mcdurdin mcdurdin added this to the A18S7 milestone Jul 26, 2024
@mcdurdin mcdurdin self-assigned this Jul 26, 2024
ermshiperete added a commit that referenced this issue Jul 26, 2024
See #12027 (as well as build failures in the current repo restructurings)
for the motivation for this change.

Basically remove all `path` lines from `references` except when they
reference files in or below the current directory. Another execption is
if there is no `package.json` file for the current directory, i.e. the
current directory is not a separate module.
ermshiperete added a commit that referenced this issue Jul 26, 2024
See #12027 (as well as build failures in the current repo restructurings)
for the motivation for this change.

Basically remove all `path` lines from `references` except when they
reference files in or below the current directory. Another execption is
if there is no `package.json` file for the current directory, i.e. the
current directory is not a separate module.
ermshiperete added a commit that referenced this issue Jul 26, 2024
See #12027 (as well as build failures in the current repo restructurings)
for the motivation for this change.

Basically remove all `path` lines from `references` except when they
reference files in or below the current directory. Another execption is
if there is no `package.json` file for the current directory, i.e. the
current directory is not a separate module.
ermshiperete added a commit that referenced this issue Jul 26, 2024
See #12027 (as well as build failures in the current repo restructurings)
for the motivation for this change.

Basically remove all `path` lines from `references` except when they
reference files in or below the current directory. Another execption is
if there is no `package.json` file for the current directory, i.e. the
current directory is not a separate module.
ermshiperete added a commit that referenced this issue Jul 26, 2024
See #12027 (as well as build failures in the current repo restructurings)
for the motivation for this change.

Basically remove all `path` lines from `references` except when they
reference files in or below the current directory. Another execption is
if there is no `package.json` file for the current directory, i.e. the
current directory is not a separate module.
mcdurdin added a commit that referenced this issue Jul 26, 2024
With the full move to ES Modules, we no longer need to include
`references` in tsconfig.json, as we can rely on package.json and
build.sh dependency management. Note however that `tsc -b` may not work
to build dependencies -- they need to be built using `build.sh`, which
calculates which dependencies need building.

kmc-keyboard-info was missing a dependency link to kmc-package in
build.sh, correcting this at the same time.

Relates-to: #12027
ermshiperete added a commit that referenced this issue Jul 29, 2024
See #12027 (as well as build failures in the current repo restructurings)
for the motivation for this change.

Basically remove all `path` lines from `references` except when they
reference files in or below the current directory. Another execption is
if there is no `package.json` file for the current directory, i.e. the
current directory is not a separate module.
ermshiperete added a commit that referenced this issue Jul 30, 2024
See #12027 (as well as build failures in the current repo restructurings)
for the motivation for this change.

Basically remove all `path` lines from `references` except when they
reference files in or below the current directory. Another execption is
if there is no `package.json` file for the current directory, i.e. the
current directory is not a separate module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant