Uh oh!
There was an error while loading. Please reload this page.
Add support for .cjs and .mjs input files - #39840
Conversation
92c08fd to
cc3f921CompareJan Olaf Martin (hybrist)
commented
Jul 31, 2020
Those examples seem to be about the resolver features, not about the file extensions. The resolver is equally "broken" for |
@jkrems you are partial right at present it is as broken as typescript is broken it self. I can not explain all that in a short comment or issue but this result is the same as we got befor 3 years :). |
Frank Lemanschik (frank-dspeed)
commented
Jul 31, 2020
I think this issue can finaly not get fixed in this way typescripts module system needs refactor much more then accepting .mjs and cjs as extension for js handling. |
Jan Olaf Martin (hybrist)
commented
Jul 31, 2020
I think you are right that a more fundamental fix may be desirable. The question is: If just letting people import So what is the path forward short term, if not a patch like this? People who want to write packages that contain (some) native ESM should stop using vscode to do it? They should use some community fork with these changes and override the project TS (which the ts language server might then pick up..?)? |
@jkrems there exists a other workaround without recode that enables that index.d.ts // interface other typescript types export import// can also export {}// that means simply any.myapp.mjs importsomefrom'some-other'myapp.mjs.d.ts // This is typescript syntax it can now import .ts .d.ts and .js types and rexport themexport*astypesfrom'./index.d.ts'export=typesThe export = is correct typescript syntax it makes now myapp.mjs import able and it will show it with correct types if you want to even import it with specifier as you would do in nodejs you can create additional myapp.d.ts // This is typescript syntax it can now import .ts .d.ts and .js types and rexport themexport*astypesfrom'./index.d.ts'export=typesFinal usageimportmyappfrom'./myapp'//will lookup myapp.d.ts while nodejs will resolve myapp.mjs all worksimportmyappfrom'./myapp.mjs'//will lookup myapp.mjs.d.ts all works |
@jkrems and the path forward is clear drop typescripts extension .ts and replace it with solutions like assert calls and jsdoc typechecking 👍 and also a flow like Comment Syntax maybe contributed to JSDoc if that does not exist |
Jan Olaf Martin (hybrist)
commented
Jul 31, 2020
I'm not sure how eslint relates to autocomplete. The following currently works in vscode without any // b.jsexportdefaultclassFoo{bar(){}}// a.jsimportFoofrom'./b.js';newFoo().// <suggests bar() as an available method>It doesn't work if |
ExE Boss (ExE-Boss)
commented
Jul 31, 2020
Frank Lemanschik (@frank-dspeed)
That is incorrect, as that patch only hacks together a way for the TypeScript language server to recognise the This PR adds proper validation, import auto‑complete and enforces that As for the |
Frank Lemanschik (frank-dspeed)
commented
Jul 31, 2020
ExE Boss (@ExE-Boss) do not get me wrong it is a good thing but microsoft will not merge it we would need to maintain a vscode fork for that and i am not joking i am fighting with them since 5+ years. Your Solution is better then nothing. And it is more then i got done till today :) So i already cherry picked it internal. but we need to make it more easy useable as sayed overall the path forward is to create or fork the deprecated language-server project then integrate for example this typescript version and create a installer for that so that existing vscode users can simple install this as additional language server |
Tierney Cyren (bnb)
commented
Aug 1, 2020
Just wanted to say thank you for doing this work ExE Boss (@ExE-Boss) 🙏🏻 |
Alistair MacDonald (F1LT3R)
commented
Aug 1, 2020
ExE Boss (@ExE-Boss) You will be remembered as a god if you pull this off. |
If some one does want to test this https://github.com/stealify/typescript npm i -g vscode-typescript@https://github.com/stealify/typescript
# Getting global path
npm root -gHit f1 on keyboard open user settings and set "typescript.tsdk": "{your_global_npm_path}/vscode-typescript/lib"restart is not needed. |
ExE Boss (ExE-Boss)
commented
Aug 9, 2020
That is the intended behaviour. |
Frank Lemanschik (@frank-dspeed) That’s because all engines (including Node.js) forbid loading native ES Modules without the file extension. // This will fail at runtime if `module-with-dts` doesn't exist in the same directory,// even if `module-with-dts.js` (or `module-with-dts.mjs`) does:import"./module-with-dts";Note that this PR makes it so that |
ExE Boss (@ExE-Boss) that is not true with the extension part we got a new I will go ahead then now with rollup-language-server to solve all that compat issues once and for ever with and without typescript 👍 thanks for your effort. |
Nathan Shively-Sanders (sandersn)
left a comment
There was a problem hiding this comment.
We're not going to add .cjs and .mjs extensions until we have a complete plan for supporting them.
Nathan Shively-Sanders (sandersn)
commented
Sep 3, 2020
A few years ago when I was working on early support for .vue files, I had pretty good luck with manually telling emacs to treat arbitrary extensions as Typescript. That might still work, although probably intra-file support won't be great. |
Nathan Shively-Sanders (@sandersn) for context, I'm interested in this support landing since it's required for VS Code to automatically update import paths with |
Frank Lemanschik (frank-dspeed)
commented
Sep 5, 2020
UPDATE* At present i expirence no down sides in the EDITOR with such Changes even not with my version that sets everything to .js |
TypeScript Bot (typescript-bot)
commented
Nov 2, 2020
The TypeScript team hasn't accepted the linked issue #27957. This makes it less likely that we'll review or accept this PR. Try to get the originating issue accepted. |
ExE Boss (ExE-Boss)
commented
Oct 13, 2021
Fixed in #45884 (TypeScript 4.5) |
I got fed up with not having IntelliSense or type checking in
.cjsand.mjsfiles, so I’ve decided to fix this myself..cjsfiles #38784