CodeSnaporaz
CodeSnaporaz10mo ago

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/22419
GitHub
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
Deno AI Helper
Deno AI Helper10mo ago
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.
CodeSnaporaz
CodeSnaporazOP10mo ago
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.
Deno AI Helper
Deno AI Helper10mo ago
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 issue
bartlomieju
bartlomieju10mo ago
Ack, i will look into the problem once I'm back at work @CodeSnaporaz when was the last time you tried deploying it?
CodeSnaporaz
CodeSnaporazOP10mo ago
No description
CodeSnaporaz
CodeSnaporazOP10mo ago
"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:
{
"imports": {
"ics" : "npm:ics"
//...
}
{
"imports": {
"ics" : "npm:ics"
//...
}
I reverted that change but it made no difference.
CodeSnaporaz
CodeSnaporazOP10mo ago
Compiles and runs in 1.39.4, breaks in 1.40.0
No description
bartlomieju
bartlomieju10mo ago
Can you try deploying again today?
CodeSnaporaz
CodeSnaporazOP10mo ago
I can now if that works for you.
CodeSnaporaz
CodeSnaporazOP10mo ago
No description
bartlomieju
bartlomieju10mo ago
Thanks. I'll be back in work on Wednesday so I'll take care of it
CodeSnaporaz
CodeSnaporazOP10mo ago
Much appreciated
bartlomieju
bartlomieju10mo ago
We've identified a fix and are working on deploying it The fix has been deployed now
CodeSnaporaz
CodeSnaporazOP10mo ago
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?
bartlomieju
bartlomieju10mo ago
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
CodeSnaporaz
CodeSnaporazOP10mo ago
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?
bartlomieju
bartlomieju10mo ago
-.- Okay, so it's in deno compile
CodeSnaporaz
CodeSnaporazOP10mo ago
I'd imagine so. But how come #deploy™ is now working?
bartlomieju
bartlomieju10mo ago
Because we updated Deploy to respect the configuration
CodeSnaporaz
CodeSnaporazOP10mo ago
does deploy use different tools from deno compile?
bartlomieju
bartlomieju10mo ago
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 it
bartlomieju
bartlomieju10mo ago
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.
CodeSnaporaz
CodeSnaporazOP10mo ago
Marvellous! In the meantime I truly appreciate the fix in Deploy.
bartlomieju
bartlomieju10mo ago
Sure thing, sorry for the problems
CodeSnaporaz
CodeSnaporazOP10mo ago
Tested 1.41.0. Working now. Thanks a lot
fro.profesional
fro.profesional10mo ago
@bartlomieju I'm currently trying to deploy this:
import "npm:reflect-metadata";
import { injectable, container } from "npm:tsyringe";

class Module {
constructor() { }

some() {
return "some"
}
}

@injectable()
class App {

constructor(
private module: Module
) { }

callSome() {
return this.module.some()
}
}

const app = container.resolve(App);

Deno.serve(() => {
return new Response(app.callSome())
})
import "npm:reflect-metadata";
import { injectable, container } from "npm:tsyringe";

class Module {
constructor() { }

some() {
return "some"
}
}

@injectable()
class App {

constructor(
private module: Module
) { }

callSome() {
return this.module.some()
}
}

const app = container.resolve(App);

Deno.serve(() => {
return new Response(app.callSome())
})
It works, locally but it fails to deploy with the following error:
error: The deployment failed: UNCAUGHT_EXCEPTION

Error: TypeInfo not known for "App"
at file:///node_modules/.deno/tsyringe@4.8.0/node_modules/tsyringe/dist/cjs/dependency-container.js:292:27
at InternalDependencyContainer.construct (file:///node_modules/.deno/tsyringe@4.8.0/node_modules/tsyringe/dist/cjs/dependency-container.js:297:11)
at InternalDependencyContainer.resolve (file:///node_modules/.deno/tsyringe@4.8.0/node_modules/tsyringe/dist/cjs/dependency-container.js:114:33)
at file:///src/main.ts:25:23
error: The deployment failed: UNCAUGHT_EXCEPTION

Error: TypeInfo not known for "App"
at file:///node_modules/.deno/tsyringe@4.8.0/node_modules/tsyringe/dist/cjs/dependency-container.js:292:27
at InternalDependencyContainer.construct (file:///node_modules/.deno/tsyringe@4.8.0/node_modules/tsyringe/dist/cjs/dependency-container.js:297:11)
at InternalDependencyContainer.resolve (file:///node_modules/.deno/tsyringe@4.8.0/node_modules/tsyringe/dist/cjs/dependency-container.js:114:33)
at file:///src/main.ts:25:23
Is that expected? I'm deploying a main.ts file and a deno.json with emitDecoratorMetadata and experimentalDecorators both set to true
bartlomieju
bartlomieju10mo ago
Does it work with Deno V1.40.4?
fro.profesional
fro.profesional10mo ago
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?
No description
CodeSnaporaz
CodeSnaporazOP10mo ago
It look like a separate issue from the decorators one. The exception is complaining about the type of App , unless I'm mising something.
fro.profesional
fro.profesional10mo ago
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 container
CodeSnaporaz
CodeSnaporazOP10mo ago
What 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?
fro.profesional
fro.profesional10mo ago
I'm only running it straight with deno run
CodeSnaporaz
CodeSnaporazOP10mo ago
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.
CodeSnaporaz
CodeSnaporazOP10mo ago
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
CodeSnaporaz
CodeSnaporazOP10mo ago
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.
fro.profesional
fro.profesional10mo ago
I’ll try that, thanks 🙏 !
CodeSnaporaz
CodeSnaporazOP10mo ago
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...
CodeSnaporaz
CodeSnaporazOP10mo ago
Pleasure. If you need help, feel free to open a topic.
CodeSnaporaz
CodeSnaporazOP10mo ago
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.
Sorikairo
Sorikairo10mo ago
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 options
CodeSnaporaz
CodeSnaporazOP10mo ago
oak-decorators doesn't rely on emitted metadata, as far as I can remember. At any rate it works with Deploy like a charm.
Sorikairo
Sorikairo10mo ago
Yes, but for fro's usecase, which is dependency injection (if I understood correctly the piece of code they gave), it probably needs it. But also just noticed it uses some npm packages, so maybe more shenanigans
CodeSnaporaz
CodeSnaporazOP10mo ago
oak-decorator does DI via the @Injectable decorator. I don't use that much in my projects as I'm but it's there.
CodeSnaporaz
CodeSnaporazOP10mo ago
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.
Sorikairo
Sorikairo10mo ago
Without it, swc and tsc do not emit constructors and methods paramstype, so DI cannot work AFAIK
CodeSnaporaz
CodeSnaporazOP10mo ago
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 😄
Sorikairo
Sorikairo10mo ago
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
CodeSnaporaz
CodeSnaporazOP10mo ago
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
Sorikairo
Sorikairo10mo ago
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)
CodeSnaporaz
CodeSnaporazOP10mo ago
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.
Sorikairo
Sorikairo10mo ago
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)
CodeSnaporaz
CodeSnaporazOP10mo ago
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.
Sorikairo
Sorikairo10mo ago
Gotcha, sad, but glad it works on Deploy for you then
fro.profesional
fro.profesional10mo ago
@Sori [He/Him] do you know of an alternative to deno bundle?
Sorikairo
Sorikairo10mo ago
I would say any bundling library such as esbuild ? I believe there were a few very valuable contribution to plugin to handle Deno well