-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
[Feature] Support transformers written as ES modules #58
Comments
Thanks for the report. ESModule support is definitely important. I'm not sure if I'm missing something, but I'm not sure how you could implement this into CJS code without dramatic rewrites. For example, the typescript compiler is a synchronous cjs file. In the case of In the case of the API (ie. Edit: I think the simple answer here is that typescript, itself, doesn't support esm transformers. Rewiring it to do so on our end wouldn't be a viable or sustainable route to take. That said, however, our current support for
Then, if it is necessary, we simply transpile ahead of time, like we do for Again, I don't have a lot of knowledge around the actual esm spec or any recent developments thereof, so if there's anything I'm not seeing, I'd be glad to be wrong! From what I currently know, I think this may be the best means of achieving support. |
Ah, interesting. It didn't occur to me that because you are patching TypeScript, it is not easy for you to add arbitrary asynchronous setup work. It is true that there is no synchronous dynamic import for ES modules. I can see that this would be quite hard to support! I'm coming over from |
We're essentially doing the same thing as Both libraries patch Actually just supporting But, this is really just me thinking out loud. I don't think any of that is relevant to the ask. The right move is to add support further upstream, like we did to natively support Have you tried using |
Does TS 5.0 being mostly ESM now change this at all? |
This is now supported in v3 |
- Added Live Compiler (on-the-fly, in-memory patching) - Added experimental ES Module support (closes #58) - Added mutex locks (closes #75) - Updated to support TS v5+ (closes #83 closes #93) - Fixed patching for non-standard libraries (cannot guarantee they will work as expected in IDEs) (closes #85) - Added caching
I'm on v3.0.2, and I'm unable to get ESM working.
It seems when Unless I'm totally mistaken here, using |
@Mexican-Man Can you make a repro? Esm requires the esm package, but it should warn you of that. The plugin path should be relative file path to the plugin file.
Sounds like your config had an issue somewhere |
@nonara It's more than likely I'm messing something up. Here's a reproduction with instructions. Please let me know if you spot anything. |
did you ever get to the bottom of this? I'm using ESM and continue to get:
Not sure how to get around it or where the issue is |
Opened a new issue here: #172 |
It is not currently possible to import a transformer that is written a standard ES module. Only transformers written as CommonJS modules work currently.
Node has supported standard ES modules since v12, so that's all currently supported versions of Node: https://nodejs.org/en/about/releases/. Node packages are increasingly being published as ES modules instead of CommonJS, so it would be great to be able to use them here too! One huge advantage of ES modules is that they can run directly both in Node and browsers.
https://nodejs.org/api/esm.html#esm_introduction
Note this doesn't require writing
ts-patch
itself in ES modules, since there is bi-directional interoperability in Node. To import an ES module from a CommonJS module, useconst mod = await import("./some-module.js")
instead ofrequire
. To check if a module should be imported as an ES module, look in itspackage.json
for the{"type": "module"}
field.I see a new version is being written at #40 -- I think this would be an awesome thing to include in the rewrite.
Thanks!
The text was updated successfully, but these errors were encountered: