Closed felixcatto closed 1 year ago
I think this part may be to blame:
The loop will check the following:
.ts
file, then add .ts
extension to the resolved paths..tsx
file, then add .tsx
extension to the resolved paths.The intended functionality according to the comment would be to add both .ts
and .tsx
in both cases.
@felixcatto node-resolve v15.1.0 was just released with my fix (see #1498). Could you verify that this solves your issue?
@meyfa Yes, it solves first two cases from this list
index.tsx 'import' utils.ts # error => works now
index.ts 'import' utils.tsx # error => works now
index.js 'import' utils.tsx # error
index.ts 'import' utils.ts # works
index.tsx 'import' utils.tsx # works
But following scenario doesn't work (I also updated a repo at first post)
index.js
import { x } from './utils.js';
console.log(x);
utils.ts
export const x = 111
Of course it is rare case, when someone want to import .ts
file from .js
file. So thanks for fix :wink:
Oh sorry, I totally overlooked that case! And it seems that this works with ts-node out of the box as well, so perhaps Rollup should support it?
I personally think it's a bit unusual to import TS from a JS file.
Initially i wanted to say "yes", but decided to look at Vite behaviour in this situation. And Vite also throws error, but it is quite popular bundler and seems people doesn't have such problems if it doesn't fixed yet. So i would say that it can be ignored.
Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it. ⓘ
Expected Behavior
When i import '.ts' file from '.tsx' file, and specify '.js' extension, it should be imported.
Actual Behavior
I get error
Additional Information
ES modules want that we add file extensions to all files https://nodejs.org/api/esm.html#mandatory-file-extensions But Typescript doesn't like '.ts', '.tsx', it want '.js', '.jsx', '.mjs', ...
But if i import utils.js, when actual files have different extension i got following error
index.tsx
utils.ts
In webpack i can define
resolveextensionalias
https://webpack.js.org/configuration/resolve/#resolveextensionaliasIn rollup nodeResolve
extensions
option seems combines webpackextensionalias
&extensions
options. But only partially. It only works if all extensions matches, i.e. all files have '.tsx'