TC39 stage 3 decorators not working anymore in Deno Deploy
As of Feb 15th, deployments to #deploy™ fail when using TC39 decorators.
Despite the decision to support legacy decorators in Deno 1.40+, see @bartlomieju 's post here https://github.com/denoland/deno/issues/19160#issuecomment-1855462766, when compiling, the
experimentalDecorators
config is ignored and I suspect any decorator, including the TS 5.0 ones, causes compilation to fail.
I'm supposed to go live in a few weeks and I my app doesn't run on Deno Deploy anymore.
https://github.com/denoland/deno/issues/19160#issuecomment-1949548670
https://github.com/denoland/deno/issues/22419GitHub
TC39 stage 3 decorators do not work with bundle or compile · Issue ...
$ deno --version deno 1.40.4 (release, x86_64-pc-windows-msvc) v8 12.1.285.6 typescript 5.3.3 The TC39 stage 3 decorators sample provided by https://deno.com/blog/v1.40#decorators does not work wit...
GitHub
Typescript 5 decorators · Issue #19160 · denoland/deno
Release 1.32.0 comes with Typescript 5.0.2. But, as per notes in this PR I see no modern (stage 3) decorators support. As far as I understand, the problem is about SWC. But SWC supports them in the...
58 Replies
I apologize, but I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided in your message, it seems like there might be an issue with the Deno Deploy compilation process regarding decorators.
While I cannot provide a solution based on the Deno documentation, I can suggest ensuring that your TypeScript configuration is set up correctly to enable experimental support for decorators if you haven't done so already. This typically involves setting the
experimentalDecorators
option to true
in your tsconfig.json
file. Please note that this advice is not based on the Deno documentation, and I advise you to double-check the accuracy of this advice.
Since this is a recent issue, it might also be helpful to keep an eye on the GitHub issues you've linked to see if there are any updates or workarounds provided by the Deno team or community. If the problem persists, consider reaching out on the GitHub issues for further assistance from the Deno developers.experimentalDecorators option is correctly set as per my comments in the github issue. This looks like a breaking change introduced by the adoption of the newest deno runtime in #deploy™ . It's likely affecting all the applications that use decorators. Any new deployment is likely to break for this applications. Seems quite serious from my perspective.
I understand the severity of the situation, especially with your upcoming live deployment. It does seem like a critical issue if the adoption of the newest Deno runtime in Deno Deploy is causing breaking changes for applications that use decorators.
Given that you have already set the
experimentalDecorators
option correctly and have provided information on GitHub, the best course of action would be to actively engage with the Deno team through the GitHub issues you've mentioned. Since this is a recent and potentially widespread issue, the Deno team is likely to prioritize a fix or provide a workaround.
In the meantime, here are a few steps you can take:
1. Monitor the GitHub Issues: Keep an eye on the existing GitHub issues for any updates or comments from the Deno team. They might provide a temporary workaround or a patch.
2. Engage with the Community: Continue to engage with the community on the Deno Discord and GitHub. Other developers might be experiencing the same issue and could have insights or workarounds.
3. Prepare for a Rollback: If possible, prepare to rollback to a previous version of your application that is stable on Deno Deploy, until the issue is resolved.
4. Local Testing: If you haven't already, try to replicate the issue locally with the same Deno runtime version used in Deno Deploy to see if you can identify any additional information that could help resolve the issue.
5. Alternative Deployment Strategies: As a last resort, consider if there are alternative deployment strategies that could be used temporarily, such as containerization, until the issue is resolved.
Remember to keep all communication with the Deno team constructive and provide as much detail as possible to help them understand and address the issuequickly. 🦕
Ack, i will look into the problem once I'm back at work
@CodeSnaporaz when was the last time you tried deploying it?
"minor changes" as in "gaaack! wth is going on?" 😄
Just to give you some further background:
I DIFFed the two commits at the bottom to see what was different. The only change was an (unused) import in deno.jsonc:
I reverted that change but it made no difference.
Compiles and runs in 1.39.4, breaks in 1.40.0
Can you try deploying again today?
I can now if that works for you.
Thanks. I'll be back in work on Wednesday so I'll take care of it
Much appreciated
We've identified a fix and are working on deploying it
The fix has been deployed now
That's impressive. Go Deno team. What was the fix? Do we have it tracked on GitHub?
Locally still fails so I suspect it's a hot-fix on #deploy™ for the time being, right?
Deploy misssed reading configuration when it was updated to the latest Deno runtime
What does file locally? Can you show me the repro? It should work correctly in any 1.40.x release
same repo that now succeeds on Deploy. It's a private one. The failure happens when executing a compiled deno app as per https://discord.com/channels/684898665143206084/1208544667038388295/1208894962830282793
I tried this morning with runtime 1.40.5. Is there any argument to be passed to
deno compile
or the executable in order for the decorators to be recognized?-.-
Okay, so it's in
deno compile
I'd imagine so. But how come #deploy™ is now working?
Because we updated Deploy to respect the configuration
does deploy use different tools from deno compile?
It uses the same tools, but there are various knobs that can be tweaked
Looks like we missed to turn the knob in
deno compile
. I'm looking into the problem right now. Can reproduce itFix incoming: https://github.com/denoland/deno/pull/22521
GitHub
fix(compile): respect compiler options for emit by bartlomieju · Pu...
deno compile was ignoring configuration file and thus not applying
compilerOptions to influence the way files were emitted.
Marvellous! In the meantime I truly appreciate the fix in Deploy.
Sure thing, sorry for the problems
Tested 1.41.0. Working now. Thanks a lot
@bartlomieju
I'm currently trying to deploy this:
It works, locally but it fails to deploy with the following error:
Is that expected?
I'm deploying a main.ts file and a deno.json with emitDecoratorMetadata and experimentalDecorators both set to true
Does it work with Deno V1.40.4?
Sorry for the late response
It works with
- deno 1.41.0 in local
- deno 1.40.4 in local
FYI: the errors I see while trying to deploy are the same as if no compilerOptions where used on local, so maybe the configuration from deno.json is not being applied?
It look like a separate issue from the decorators one. The exception is complaining about the type of
App
, unless I'm mising something.It complains that the
TypeInfo not known for "App"
since the decorators are not working, when they work (in local for example) there is no error
This decorators help to inject at runtime a instance of the given class when resolvig from the containerWhat I'm trying to say is that, if the runtime gets to dependency-container.js in relation to App, it seems to mean that the decorators are recognised as such. It looks like a red herring to me. Surely, if there's something that won't work in Deploy, that suggests that there are differences in the way the app is running. Have you tried running the app as a compiled bundle or are you only running it straight with
deno run
?I'm only running it straight with
deno run
ok, I'd suggest you try to compile it and run the executable. If you get the same issue locally, you might be able to isolate the problem more easily.
As a side note, are you at the beginning of your project? I see that tsyringe is an node package. I'm successfully using Oak-decorators, which I updated myself, successfully. At the moment I'm importing it from a github fork as I yet have to find the time to do the pull request. https://github.com/cleverplatypus/oak-decorators
GitHub
GitHub - cleverplatypus/oak-decorators: Project implements decorato...
Project implements decorators for oak like Nest.js. - Replaced reflect_metadata with deno_reflect - cleverplatypus/oak-decorators
I suspect the project was abandoned because reflect_metadata was a dud that prevented the whole thing from working. Luckily deno introduced the scopes configuration, which allowed me to add the drop-in replacement.
I’ll try that, thanks 🙏 !
https://github.com/biga816/oak-decorators/pull/1 now pull-requested 🙂
GitHub
Added support for custom decorators, made it work with deno_reflect...
Hey, I found this good project, it looked like it wasn't very active, possibly because the dependency with reflect_metadata was preventing it from working at all, at least in recent versions of...
Pleasure. If you need help, feel free to open a topic.
lastly, a bit of shameless self-promotion, if you feel like using/supporting any of my npm packages...
https://www.npmjs.com/package/http-request-factory (Deno compatible)
https://www.npmjs.com/package/tiny-object-validator (Deno compatible)
https://www.npmjs.com/package/signals.ts (Deno compatible)
https://www.npmjs.com/package/vue3-routable (Vue3 -duh - if you use Vue and like decorators)
npm
http-request-factory
!GitHub release !. Latest version: 0.0.19, last published: 9 days ago. Start using http-request-factory in your project by running `npm i http-reque...
npm
tiny-object-validator
Small library to organise JavaScript/TypeScript objects' validation. Latest version: 1.0.1, last published: a month ago. Start using tiny-object-validator in your project by running
npm i tiny-object-validator
. There are no other projects in the npm registry using tiny-object-validator.npm
signals.ts
!Tests. Latest version: 1.0.4, last published: 21 days ago. Start using signals.ts in your project by running
npm i signals.ts
. There are no other projects in the npm registry using signals.ts.npm
vue3-routable
Small utility to annotate classes of objects to be activated/deactivated upon vue-router routes change . Latest version: 0.1.8, last published: 6 months ago. Start using vue3-routable in your project by running
npm i vue3-routable
. There are no other projects in the npm registry using vue3-routable.Dropping in because oak decorators is really close to https://github.com/Savory/Danet
Last time I checked around 6 months ago, deploy does not handle
emitDecoratorsMetadata
while the runtime does,so if you rely on paramstype metadata it won’t work. Maybe it has been implemented since @bartlomieju ?
If it has not been implemented/fixed yet, @fro.profesional you have to first bundle your app in your ci/locally with the emitDecoratorMetadata options and then upload the bundle to deploy. Here is a guide to do so https://danet.land/deno-deploy.html
It is made for Danet app but the concepts apply to any app that uses decorators and thus specific compiler optionsoak-decorators doesn't rely on emitted metadata, as far as I can remember. At any rate it works with Deploy like a charm.
oak-decorator does DI via the @Injectable decorator. I don't use that much in my projects as I'm but it's there.
https://github.com/cleverplatypus/oak-decorators/blob/master/tsconfig.json
has
emitDecoratorMetadata
Danet is a complete solution (framework as they describe it) I guess oak-decorators is a discrete library that works on top of Oak, so I guess that if someone is familiar with Oak, it's an easy addition.
might be in the config, doesn't mean it's relied upon.
Without it, swc and tsc do not emit constructors and methods paramstype, so DI cannot work AFAIK
I seem to remember that, when I looked into it, I noticed that it was keeping a custom hash of metadata. I might be wrong. Once it was working, I stopped looking 😄
But then, if you say that it works on Deploy without any bundling (and I believe you) it either means Deploy handles it now, or they do it another way. In both case, that's awesome
It always worked once I replaced reflect_metadata with deno_reflect
the issue with reflect_metadata I think was some dependency with microsoft stuff or dom, don't remember
But deno_reflect also need
emitDecoratorMetadata
as stated by their doc https://deno.land/x/deno_reflect@v0.2.0
(it's also what Danet uses)I think they guy who first wrote oak-decorator bumped into the issue and found a workable strategy. I just stood on the shoulder of such giant and added some customisation that served me well.
Do you have any open source repo of a project you deployed on Deno deploy that uses it by any chance ? it's on the back of my head for 2 years, if it gives me a resolution it would be cool (already starring all the repo you linked, for fairness)
Not open source ones, I'm afraid. Working on a couple of commercial products at the moment. They both use oak-decorators.
One should launch in a few weeks.
Gotcha, sad, but glad it works on Deploy for you then
@Sori [He/Him] do you know of an alternative to deno bundle?
I would say any bundling library such as esbuild ? I believe there were a few very valuable contribution to plugin to handle Deno well