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

vite-tsconfig-paths cannot import a basic TSconfig extends in sub-folder #150

Closed
matthew-dean opened this issue Jul 31, 2024 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@matthew-dean
Copy link

I've reduced the test case to this: https://stackblitz.com/edit/vitest-dev-vitest-oip9io?initialPath=__vitest__/

You can see that this Vite plugin fails entirely to resolve paths using TSConfig settings.

It's important to note that:

  1. The app itself and TypeScript compiler work fine with this setup. Paths are always relative to their tsconfig.json file, but vite-tsconfig-paths does not account for that, and incorrectly merges path options.
  2. In my actual use case, I do not have control over extending from a sub-folder nor the paths. They are auto-generated by Nuxt.
@matthew-dean
Copy link
Author

Note also that without parseNative, the plugin failed wildly, not just on path resolution, as there are multiple tsconfig.json files that extend from others in a Nuxt setup. But even if resolving "natively", it's not actually resolving natively in the way that TypeScript actually understands those paths.

@juni0r
Copy link

juni0r commented Sep 9, 2024

@matthew-dean Did you find a fix?

@aleclarson
Copy link
Owner

In the case of @matthew-dean's reproduction, the fix is to set baseUrl in the .config/tsconfig.json file to ../ and replace the ../ prefixes in the paths array with ./ prefixes.

Example .config/tsconfig.json file

{
  "compilerOptions": {
    "target": "es2020",
    "module": "node16",
    "moduleResolution": "Node16",
    "strict": true,
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "verbatimModuleSyntax": true,
    "baseUrl": "../",
    "paths": {
      "~": ["./src"],
      "~/*": ["./src/*"]
    }
  },
  "include": ["../src", "../test"],
  "exclude": ["../node_modules"]
}

This has an unfortunate side effect of allowing src/basic.js as an import specifier, due to how the baseUrl option works.

The ideal solution is for someone to contribute a fix to tsconfck that rebases paths inherited from an extended tsconfig (see here for relevant code).

@aleclarson
Copy link
Owner

Fixed in v5.1.4

renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 7, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 8, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
@mamunonweb

This comment was marked as off-topic.

@aleclarson
Copy link
Owner

aleclarson commented Dec 8, 2024

Hi @mamunonweb, that's not related to this issue. Try reproducing your issue in the test suite by tweaking the paths-outside-root test fixture until it fails. You can run the test with this command:

pnpm vitest -t paths-outside-root

renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 10, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 11, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 12, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 14, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 15, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 16, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 16, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 16, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 16, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 21, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this issue Dec 22, 2024
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | vite-tsconfig-paths | 5.1.3 | 5.1.4 |


## [v5.1.4](https://github.com/aleclarson/vite-tsconfig-paths/releases/tag/v5.1.4)

-   **fix:** correctly infer the `paths` root dir ([`eea1c17`](aleclarson/vite-tsconfig-paths@eea1c17)) ([#150](aleclarson/vite-tsconfig-paths#150))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants