-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Support ".mjs" input files #27957
Comments
I believe that #18442 tracks compiling typescript to mjs. Do we fully support working with mjs files in the editor? |
We don't lookup or include |
Since the other thread tracks |
I think it comes down to a standardization issue: javascript modules must have a standardized file extension. It's causing troubles to us, and I believe everyone who are making modules targeting for both browser & node are affected. In browser, we have to specify file name with extension: But vscode doesn't recognize Then node doesn't recognize This is surely uncomfortable since you have to specify a non-default loader. Either node has to support I personally think module javascript files gotta have a different extension since it's treated differently in both browser & node. Browsers require: I prefer I just hope es7/8 standard specify that javascript modules must have |
I crafted a patch which enables This might be useful for people who use the .mjs file extensions for JavaScript files with identical module resolution semantics as CommonJS. Note that this patch does not implement any special behaviour with regard to ES modules and might not be spec-compliant. However, editor integrations which allow using custom-built |
Thanks for the patch, @robertrossmann! Btw, I just realized that |
As of last October, there’s agreement on the “minimal kernel”, which states that:
|
In other words, there’s no point in waiting. |
is there any stop-gap workaround that we are aware of? |
Hey @weswigham, can you please bump the priority on this issue? This is currently preventing anyone who uses TypeScript from building a custom service worker bundle with Workbox, since Workbox's source code is published as Workbox users can do this with Webpack, they can do it with Rollup, and they can do it with Parcel, but they can't do it with TypeScript, and many of our users are TypeScript users. From the above discussion it sounds like you wanted to wait to see where node landed on It's a real blocker for a lot of people, and it's not something we can change on our end since that would break people's existing builds. There are also lots of other modules (browser modules, not just node-specific modules) that are published to npm with I don't see any downside to TypeScript recognizing |
Aside from the actual TS inputs, click-through in VS Code (e.g. |
The Article got Partial pasted into a discussion in microsoft/TypeScript#27957 (comment) and i found out that it makes false claims that confuses new users. So i corrected the relevant parts as the Users do not understand that we migrate forward to ESM and not ship old none needed CJS if it is not needed.
@igorskyflyer mdn/content@main...frank-dspeed:patch-1 i will patch the MDN Article thanks for your input. it Helps us to identify Areas where the information is not as clear as it should be |
@frank-dspeed, I agree, I am for that too but we are not there, yet. This is my opinion during this transition period until there is one standard in both Node and browsers. Also, the opinions I stated above are based purely on (available) facts and personal experience, I never said it makes the code better in any way, more compatible - yes. Sidenote, this issue is about |
@igorskyflyer thats true without patching typescript there is no chance and the typescript philosophie is against that you need to wait for alternativ resolve algo support. maybe it already even works i am not so deep into that. but there are internals to allow diffrent resolve strategies. for example import maps maybe already work and package,json works already or adding // @ts-check on top of the file also works |
@petamoriken can you please explain more deep why this is related to the deprecation of existing mime types ? |
@frank-dspeed This draft also includes the adoption of .mjs as the new file extension for JavaScript 🙂
https://datatracker.ietf.org/doc/html/draft-ietf-dispatch-javascript-mjs-09#section-3 |
@petamoriken i only read SOME (NodeJS) scripting environments have chosen ...... The Browser will stay with mime headers There is 100% sure zero effort in changing that. The Script Parsing type inside the browser gets declared via the script type the headers will stay the same. NodeJS is the only driver for .mjs Out of Browser view
Exampleto be more clear this will never work with esm modules! <script src="/my.mjs"></script> and this will always work <script src="/my.mjsOrNoMatterwhat" type="module"></script> Out of Typescript view
Out of NodeJS viewby the way the only none well speced implementation that supports a lot of mixUps
Out of Embeddeder viewEmbedders are projects that are using v8 or other popular engines directly
|
@frank-dspeed, just to be clear, this: <script src="/myModule.mjs"></script> was never proposed nor supposed to work - as far as I am aware of. The attribute <script src="/myModule.mjs" type="module"></script> Also, |
@igorskyflyer i did list all requirements including the mime header and in my example i did .mjsOrAny to demonstrate that it has nothing to do with the extension. and your correct without type it is not suposed to work you maybe did not read the whole story. |
@frank-dspeed, my apologies then, I skim-read the comment. Either way, it is evident that we are still waiting for a unique solution for this mjs/modules hell. 😭😅 |
@IgorNovozhilov There is no real module hell anymore the way forward is clear simply drop cjs usage call the files .js and configure typescript correct per folder. Sure i agree it is a lot to know and do but it is not unsolved at all and .mjs remains a nodejs only topic. Update for thumbs downI want to offer some more detailed Information as there are still people who did not get it. also this got now fixed via a new moduleResolution algo called "node12" as this is a node only thing |
Fixed by the addition of |
typescripts now supports .mjs microsoft/TypeScript#27957
typescripts now supports .mjs microsoft/TypeScript#27957
this future will only be in typescript 4.6 it got droped from the 4.5 time schedule #46452 (comment) as Daniel (TypeScript Team Lead) pointed out |
(Technically support did ship in 4.5, it relies on the |
@weswigham does nodenext include everything that was included in node12 (package.json exports fild)? |
They're mostly the same (except for some export map edge cases and the implied target), and both modes are included. |
Is this really fixed? It doesn't seem so, at least not in all use cases. Particularly, there is no way to support a mixture of For the reason why, see my comment on #50985. This should be reopened. |
From @Sti2nd on October 7, 2018 16:17
import { timpaniSounds } from "./soundImport.mjs";
In the above example VS code will show all javascript files when writing "./", but not javascript module files. So I didn't see the above file in the list when trying to import it.
Not sure if this is a bug or a feature request.
Copied from original issue: microsoft/vscode#60103
The text was updated successfully, but these errors were encountered: