-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Suppressing "The import path cannot end with a '.ts' extension" error? #27481
Comments
Suppose you have two files: When we compile Instead, you should omit the file extension from your imports, or use the |
no,I use deno exec the file 。 without compile。 |
@hooper-hc
|
I'm using deno as well. I found that commenting
Is there anyway to shut this requirement off globally in ts-config? I also tried @zhmushan's solution and It didn't fix the issue :( |
@reggi remove |
Would the TypeScript team be open to adding import module from 'module'; it would show an error like |
This seems like a duplicate of #11901 which was unfortunately closed and silenced. This is important for Deno as was said before and I hope TypeScript will make this extension check configurable or even better remove it altogether. |
In most of the Javascript tooling ecosystem, you can do things like Typescript, on the other hand, expects you to either use a blank extension or the If tsc wanted to work more like the rest of the world, it could allow |
typescript should not enforce this hopefully microsoft/TypeScript#27481 will get addressed
Adding my vote here for support for Deno. The current behavior results in TypeScript resolving all types imported in this way to |
Deno's a great idea, but trying to convince the TS team to explicitly allow Deno to resolve modules that way to me is a losing battle. It's much easier for Deno just to handle it because (a) way faster to do so, less effort needed and (b) convincing the TS team to rewire its internals like that is a very uphill battle.
TS is becoming increasingly dominant, it's a good strategy to be as compatible as possible to TS conventions including their tooling. Otherwise projects like Deno will never get traction due to the divergence in something as fundamental as module resolution |
@jpike88 I disagree. I didn't realise this issue existed. There were a couple other issues semi-related which we were tracking. This issue doesn't say anything about the intent of the team. It is still labelled as a question and it could be argued it really is a duplicate of #16577 or #18442. Ryan's comment though gets to the heart of the problem, that they can possible write out something that satisfies every host, so they restrict it to the most common situation today, which is Node.js's CJS way. I still think (and I thought I said this in an issue before) is that there might be time for |
Ok, but: #18442 #16577 I'm just going off the timescale things have been happening for here, and basing their likelihood of ever happening in a medium-term or even long-term timeframe off that. |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
Similar issue occurs if you want to directly import an |
Sadly, we can't do imports without TS screaming bloody murder in Vim: An import path cannot end with a '.d.ts' extension etc Related: microsoft/TypeScript#27481 We can suppress the error, but either way, the editor can't see the types, sadly obviating one of the big upsides of using TypeScript.
Sadly, we can't do imports without TS screaming bloody murder in Vim: An import path cannot end with a '.d.ts' extension etc Related: microsoft/TypeScript#27481 We can suppress the error, but either way, the editor can't see the types, sadly obviating one of the big upsides of using TypeScript.
This is closed, but it's not fixed. |
If anyone here was just looking for a way to be able to run your TypeScript within both the context of Node.js and Deno, know that Webpack + ts-loader will let you keep ".ts" in your imports. |
This comment was marked as duplicate.
This comment was marked as duplicate.
Removing the .ts when importing solved it for me. i.e |
Thanks for the hint, I found the issue. I exported this as part of a npm package but moq.ts was not in the dependencies, only in devDependencies. If you then use the package in a project that does not include moq.ts, the issue pops up. |
just needs to remove the
|
Unfortunately that wouldn't work in Deno. |
How come this issue is open for 5 years (!!) with no answer or progress whatsoever? |
Using this separate VS Code extension worked for me: https://marketplace.visualstudio.com/items?itemName=ameerthehacker.deno-vscode&ssr=false#overview I'm using Deno and importing .ts files. Not an ideal solution, but at least there's something. |
@andy-ms
Late to the party, but why won't TypeScript change import specifiers? It seems rather odd that the file is named |
I use custom loaders in Node.js and I cannot stop VSCode from issuing error messages telling me that imports "cannot end" with various file extensions, which is now strictly false no matter what runtime is in use. Why not allow users to set an option to avoid this? |
As of about a month ago, you can use:
In your |
When doing do, I get the following error instead.
I just want to be able to use TypeScript and ES6 modules together :c |
@Higgs1 what runtime environment is your code executing in? |
Currently Deno and modern, standard compliant web browser(s) (Chromiums). Supporting Node too would be nice, but not necessary. |
While there is no fix from tsc itself (the #11901 has been closed to collaboration since Jul 2018), I had to write this small script called fix-tsc-es-imports that can be integrated into the building process just after tsc. It adds a |
@danb4r Thank you for trying to singlehandedly fix a critical tsc bug. Although using sed is rather hacky, it seems to work very well. It doesn't support dynamic imports (even with a string literal, e.g. |
Thank you @Higgs1. I will add a dynamic imports fix with string literals on the next forthcoming version. Although, dynamic imports with variables would be out of the scope of the tool. As you mentioned, that is indeed a hack while the tsc team does not fix that in the compiler itself. I'll be glad to deprecate the package as soon as we see tsc doing that job for us. In the meantime, to deal with dynamic imports with variables I think the best option would be to use tsc as a type checker and type generator, and use Babel's @babel/plugin-syntax-dynamic-import or use Babel ^7.8. |
Similar to what @danb4r said and done. This issue is important, which is why ts-add-js-extension was made, the strength of this package is that, it can also find whether you are importing/exporting |
Can this be re-opened please? I just hit it when trying out node's new EDIT: This turns out to be because typescript-language-server, which is where I got my |
From @hooper-hc on September 30, 2018 8:45
when i use
import { PI } from './module.1.ts'
import an module .
vscode linter notice me an error
'The import path cannot end with a ".ts" extension. Consider changing to import “./module.1”。'
hao can i hidden the notice ?
Copied from original issue: microsoft/vscode#59690
The text was updated successfully, but these errors were encountered: