"Default TypeScript Aurelia 2 App" template broken - `host` undefined

Hi guys,

I have just tried to create new Aurelia 2 app with npx makes aurelia, choosing:

Default TypeScript Aurelia 2 App

After running:

npm install
npm start

Aurelia 2 application brakes in the browser with following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener')
    at aurelia.js?v=d61b605d:16628:14
    at onResolve (aurelia.js?v=d61b605d:433:10)
    at new AppRoot (aurelia.js?v=d61b605d:16626:28)
    at _Aurelia.app (aurelia.js?v=d61b605d:16754:17)
    at _Aurelia.app (aurelia.js?v=d61b605d:20435:18)
    at _Aurelia.app (aurelia.js?v=d61b605d:20415:27)
    at main.ts:5:4

Line that breaks is:

host.addEventListener("submit", (e) => {
          const target = e.target;
          const noAction = !target.getAttribute("action");
          if (target.tagName === "FORM" && noAction) {
            e.preventDefault();
          }
        }, false);

because host is undefined. This line is part of AppRoot class and it’s constructor.

What am I missing here? How do I fix this error?

What operating system are you seeing this happen on? I just tested on macOS and it worked for me.

1 Like

Hi,

I tried to Windows 11 and on latest Chrome browser (138). Node v22.17.0 (LTS) and npm v11.4.2.
Altough, I don’t see how this can be connected to OS, because it seems that build finishes without any error.

The error I posted is from browser, when I open the main url. I get only a completely blank page and error in browser’s console.

Update I tried on Windows 10 machine (same version of Chrome, Node and npm) and the project starts in browser (“Hello World” stripe on top). So it is broken on Windows 11. Interesting.

Just asking about the operating system as the way dependencies are installed via Npm differs to macos (some packages get built).

That’s really quite bizarre the operating system difference but same setup caused issue. I’ll look into this on my Windows machine too.

1 Like