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

fix: bad baseUrl when project name matches folder #235

Closed
wants to merge 2 commits into from

Conversation

acorn1010
Copy link

@acorn1010 acorn1010 commented Feb 21, 2025

This will fix #205: When an aliased subdirectory has the same name as the project folder, tsc-alias can fail to replace import aliases, causing imports to fail at runtime.

For example, before the following would fail:

[
    "/home/acorn/cloud/Projects/js/foony/services/games/pool/lib/services/games/pool",
    "/home/acorn/cloud/Projects/js/foony/services/games/pool/lib/shared/src/games/pool",
]

This is because the name of the import alias folder, "pool", matched the name of the project.

This will fix justkey007#205: When an aliased subdirectory has the same name as the project folder, tsc-alias can fail to replace import aliases, causing imports to fail at runtime.

For example, before the following would fail:
[
"/home/acorn/cloud/Projects/js/foony/services/games/pool/lib/services/games/pool", "/home/acorn/cloud/Projects/js/foony/services/games/pool/lib/shared/src/games/pool"
]

This is because the name of the import alias folder, "pool", matched the name of the project.
Sorry, surprised this wasn't picked up by my IDE!
@justkey007
Copy link
Owner

@acorn1010 Tests failed!
image

@justkey007 justkey007 closed this Feb 25, 2025
@acorn1010
Copy link
Author

acorn1010 commented Feb 26, 2025

Interestingly, this "works on my machine". How are you running these tests?

The tests work for me with pnpm v7.33.7 and node v16.13.1 and npm v7.24.2. These are the versions I saw in your .github/workflows/ci.yml.

Steps to reproduce: nvm use 16; npm i -g pnpm@7; pnpm i; pnpm test

image

If I try with npm v10.9.0 and node v20.12.2, then it fails with the error you're seeing. However, it fails on master, meaning it wasn't this PR that caused this to fail.
image

Steps to reproduce: nvm use 20; npm i; npm test

The reason this happens is because:
../../node_modules/@types/node/globals.d.ts(72,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'AbortSignal' must be of type '{ new (): AbortSignal; prototype: AbortSignal; abort(reason?: any): AbortSignal; timeout(milliseconds: number): AbortSignal; }', but here has type '{ new (): AbortSignal; prototype: AbortSignal; }'.
image

Which happens because the project is configured for node v17:
image

If you want your tests to pass on master, and you're set on using node >= 20 instead, you can simply update your devDependencies for @types/node to v20. e.g.:
image

@justkey007
Copy link
Owner

@acorn1010 Recreate the PR by updating it with the master branch so that the test workflow can be triggered. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tsc-alias has bad baseUrl when project name matches folder in external alias
2 participants