aurelia: bindable decorator should not be giving a runtime error

🐛 Bug Report

bindable decorator is giving a runtime error.

🤔 Expected Behavior

should not give the error

😯 Current Behavior

bindable decorator is giving runtime error:

Uncaught TypeError TypeError: Cannot read properties of undefined (reading ‘au:annotation:bindables’) at decorator (c:\Users\dkent\Documents\Projects\douglaskent\node_modules@aurelia\runtime-html\src\bindable.ts:102:40) at bindable (c:\Users\dkent\Documents\Projects\douglaskent\node_modules@aurelia\runtime-html\src\bindable.ts:110:5)

It is happening on this line:

https://github.com/aurelia/aurelia/blob/9aeeffa86c20bd87aa87761b57244e9d84eb794f/packages/runtime-html/src/bindable.ts#L101

where context equals the string “inline” and context.metadata is undefined.

baseline equals ‘au:annotation:bindables’

💁 Possible Solution

🔦 Context

I’m stuck. The app won’t run. You may reproduce as follows:

  1. clone the repo and look at this commit: https://github.com/dkent600/douglaskent/commit/1a5de33f0fd1effdcff7285ff5fbdead83042a00
  2. run npm install
  3. run ‘npm run start’

You will see the error message in the browser console.

💻 Code Sample

I am using this repo at this commit: https://github.com/dkent600/douglaskent/commit/1a5de33f0fd1effdcff7285ff5fbdead83042a00

🌍 Your Environment

Software Version(s)
Aurelia v2.0.0-beta.17
Language Typescript, v5.4.2
Browser Edge
Bundler vite and rollup
Operating System Windows 11
NPM/Node/Yarn NPM 10.5.0

Definitely love Aurelia, for a long time

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28 (14 by maintainers)

Most upvoted comments

This setting does fix the issue. I will put it in our WIP vite skeleton.

export default defineConfig({
  esbuild: {
    target: 'es2022',
  },

Sounds like

    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,

is the temporary solution here before esbuild follows tsc behaviour.

@3cp I tried that before (see above) but it results in the runtime error:

TypeError: Cannot read properties of undefined (reading 'addInitializer')

Oh yes. Probably esbuild’s decorator helper (in the compiled code) is for legacy decorator spec (honours experimentalDecorators), while Aurelia’s decorator is using latest spec.

relax it to “^…”?.

Yes we should, completely missed it, thanks @3cp

@dkent600 I tried to debug by removing everything and only had these:

  • main.ts

    @dec
    class App {}
    
    function dec() {
      console.log('???');
    }
    
    document.body.textContent = String(new App());
    
  • vite.config.ts

    export default defineConfig({
      server: {
        port: 9000,
        strictPort: true,
      },
    })
    

And it still couldn’t compile the decorator! Will check further.

Hi @dkent600, it seems like a vite+esbuild issue. As the latest esbuild added support for the native decorators, it is worth updating the version of esbuild. Moreover, as the parameter decorators are not yet supported by the new decorator specs, those instances needs to be refactored. The Au2 release notes mention this.

I have tried the aforementioned changes in your repo. Here is a change.patch that you can apply and check.

However, it seems that the decorators are still not transpiled. Unfortunately, I am not much familiar with vite and/or esbuild. @3cp @bigopon Do you guys notice anything configuration change that needs to be made in order to transpile the code view vite/esbuild?