-
-
Notifications
You must be signed in to change notification settings - Fork 154
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 in 4.16.3 broke use of certain libraries when allowJs is true #640
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Thanks for the issue and minimal reproduction. Looks like the TS resolver is trying the Will try to look into a fix later this week. If anyone is interested in helping, feel free to contribute constructively by identifying the problem and proposing solutions. |
While debugging this today, I found a difference between I was able to work around this in my code by using the import {parsePhoneNumber} from 'libphonenumber-js/core';
import minimalMetadata from 'libphonenumber-js/min/metadata';
console.log(parsePhoneNumber('+61491570006', minimalMetadata).isValid()); This could be because {
/* snip */
"exports": {
/* snip */
"./metadata.min": {
"import": "./metadata.min.json.js",
"require": "./metadata.min.json"
},
}
} I haven't dug into this further as I don't use much from |
I dug a little further and I think that diff --git a/src/utils/map-ts-extensions.ts b/src/utils/map-ts-extensions.ts
index 34f3a68..6af9e3e 100644
--- a/src/utils/map-ts-extensions.ts
+++ b/src/utils/map-ts-extensions.ts
@@ -47,6 +47,9 @@ export const mapTsExtensions = (
);
}
+ // If we're guessing extensions, and the file _has_ an extension, start with it.
+ if (!tryExtensions && extension) tryPaths.push(filePath);
+
const guessExtensions = (
(
!(filePath.startsWith(fileUrlPrefix) || isFilePath(pathname)) Currently when resolving When resolving If I add in the line above to try the original file if it has an extension, then the This might also explain a pretty significant slowdown I am seeing in how quickly |
To resolve this, tsx will need a custom CJS resolver. The native CJS resolver has limitations, especially in extending the export map resolution behavior, which prevents a fix with the current setup. Additionally, there's a problematic discrepancy between tsx's CJS and ESM resolvers. Creating a custom CJS resolver could also address other problems where passing in conditions is necessary. One potential solution I'm considering—but haven't yet explored—is switching to the Oxc resolver. |
I don't know the intricacies of module resolution, but it seemed like things were okay with I was thinking I could make a small PR with the change above, but if it doesn't actually make sense I am ok to wait for an alternative solution based on Oxc. |
Acknowledgements
Minimal reproduction URL
https://stackblitz.com/edit/node-epykqv
Problem & expected behavior (under 200 words)
From and including version 4.16.3 of
tsx
, the bug caused the following problem:If
tsconfig.json
contains a compiler option ofallowJs
set totrue
:Then certain packages will fail when used with
tsx
. From the minimal reproduction URL, usinglibphonenumber-js
andtsx
, a simple call will result in the following error:index.ts:
Bugs are expected to be fixed by those affected by it
Compensating engineering work will speed up resolution and support the project
The text was updated successfully, but these errors were encountered: