You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tsx is able to resolve to .js and .ts files but fails to resolve .tsx files when trying to import using a .js extension in a Typescript ESM project.
For example:
import { MyComponent } from './MyComponent.js'
The import statement above should resolve to ./MyComponent.ts or ./MyComponent.tsx as per this discussion and the official TS docs. Typescript will not rewrite import statements (specifically the extension) when transpiling, so the .js extension is required in import statements inside ESM projects. This is so the transpiled code can correctly resolve to the final target file.
However, I'm geting this error when using tsx:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '<REDACTED>/MyComponent.js' imported from <REDACTED>/index.ts
It works perfectly fine when using ts-node (specifically ts-node-esm) and also when building with tsc
Bug description
tsx
is able to resolve to.js
and.ts
files but fails to resolve.tsx
files when trying to import using a.js
extension in a Typescript ESM project.For example:
The import statement above should resolve to
./MyComponent.ts
or./MyComponent.tsx
as per this discussion and the official TS docs. Typescript will not rewrite import statements (specifically the extension) when transpiling, so the.js
extension is required in import statements inside ESM projects. This is so the transpiled code can correctly resolve to the final target file.However, I'm geting this error when using
tsx
:It works perfectly fine when using
ts-node
(specificallyts-node-esm
) and also when building withtsc
Reproduction
https://stackblitz.com/edit/stackblitz-tsx-esm-bug?file=index.ts
Environment
Can you work on a fix?
The text was updated successfully, but these errors were encountered: