Error: The identifier HTMLVideoElement has not been declared

Encountering an issue while attempting to build my Angular 9 Universal project for SSR:

/Users/my-project/dist/server.js:28676
        Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__metadata"])("design:type", HTMLVideoElement)

ReferenceError: HTMLVideoElement is not defined

Utilizing the mat-video player in my project, which seems to be triggering the error. Any suggestions on how to resolve this?

Here's a snippet from my tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "module": "esnext",
    "resolveJsonModule": true,
  }
}

Answer №1

After a long week of troubleshooting, I finally managed to get it working!

I encountered the same issue:

HTMLVideoElement is not defined

Even though my environment was slightly different from what the original poster had, the solution remained consistent - avoid executing the HTMLVideoElement code.

In my case, I was using pixi.js with Angular Universal for Server Side Rendering (SSR).

To set up SSR in my Angular application, I followed the instructions provided at https://angular.io/guide/universal, by running

ng add @nguniversal/express-engine
.

The problem was resolved when I refrained from using the problematic pixi.js code:

PIXI.Texture.from('assets/image.png');

This particular call referred to HTMLVideoElement in the function signature, as outlined here:

To overcome this issue, I switched to utilizing PIXI.Loader() for loading textures instead:

this.loader = new PIXI.Loader()
this.texturesArray.forEach((texture: string) => this.loader.add(texture))
this.loader.onComplete.add(this.onTexturesLoaded)
this.loader.load()

By making this change, the problem vanished, and now my server starts without any hitches.

Additionally, I had to modify the "compilerOptions" in tsconfig.server.json by adding the property:

"module": "commonjs"

For those who are interested, here's the finalized version of my server.ts code:

(server.ts code snippet provided)

And for implementing mockCanvas, essential for working with PIXI, the function looks like this:

(mockCanvas function snippet provided)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Injecting a component in Angular 2 using an HTML selector

When I tried to access a component created using a selector within some HTML, I misunderstood the hierarchical provider creation process. I thought providers would look for an existing instance and provide that when injected into another component. In my ...

Issues arising from an aging Angular project

I'm currently facing an issue with installing node and typescript for an older angular project that I have inherited. This project is using angular 2.4.10 After downloading and installing node version 6.9.5 from the executable file, I proceeded to in ...

What is the reason for observables not being subscribed to in NgRx effects?

My understanding was that in Angular, observables will not run unless they are subscribed to. However, when examining rxjs effects, the coding often appears like this: getProcess$ = createEffect(() => this.actions$.pipe( ofType(ProcessActions. ...

Empty results in NgRx Parameterized Selector

Having trouble implementing a parameterized query in NgRx and receiving empty results. Check out the StackBlitz version of the code here: https://stackblitz.com/edit/ngrx-parameterized-query Update to Reducer Code export const userAdapter = createEntity ...

The type '{ domain: string; parent: string; }' cannot be assigned to type 'string'. Error code: ts(2322)

Hello there! I am new to TS, so thank you for taking the time to read this. The problematic line in my code is: <this.RenderPostLink domain={r.domain} parent={r.parent} /> where I encounter an error. RenderImages = (): React.ReactElement => ...

Trouble communicating between Angular HttpClient POST request and Spring Controller

I'm encountering difficulties while trying to perform a POST request from my Angular frontend service class to the backend Spring controller. Despite my efforts, I am unable to see the log.info message from the controller unless I manually trigger th ...

The issue of "Angular library throwing an error outside the specified 'rootDir' directory" arises while attempting to share dependencies

I've been hearing a lot about being able to utilize modules, components, and interfaces in an Angular library. However, I'm constantly encountering an error that says outside of the configured 'rootDir'. projects - app - lib - c ...

Exploring the Potential of Jest Testing for Angular 6 Services

Hey there, I seem to be facing a bit of a roadblock and could use some assistance. Here's the situation - I'm trying to test a service using Jest, but all the tests pass without any issues even when they shouldn't. Here are the details of t ...

How do you verify an OpenID Connect access token produced by Azure AD v2 in an ASP.NET Core web API?

What is the best way to verify an OpenID Connect Access Token generated by Azure AD (v2) in ASP.NET Core Web API? Here's the situation: I have an Angular 8 Client Application that receives an OpenID Connect access Token post Login. The Client can us ...

The @angular/fire package is unable to locate the AngularFireModule and AngularFireDatabaseModule modules

I am facing some challenges while trying to integrate Firebase Realtime Database into my Angular project. Specifically, I am encountering difficulties at the initial step of importing AngularFireModule and AngularFireDatabaseModule. To be more specific, I ...

Combining all code in Electron using Typescript

I am currently working on developing a web application using Electron written in Typescript and I am facing some challenges during the building process. Specifically, I am unsure of how to properly combine the commands tsc (used to convert my .ts file to ...

Incorporate a linked select dropdown into the registration form

I am working on a sign-up form and trying to integrate 2 linked select boxes into the form. The code for the linked select boxes works fine separately but when I attempt to add it to the form, it doesn't display as expected. I attempted to incorporate ...

Navigating through nested objects in a combined type

Is there a way to create a function that can take an object (which is part of a union) with a specified path and return the value of the config object for that specific path? I've been attempting the following: type Cat = { config: { meow: stri ...

How do I incorporate global typings when adding type definitions to an npm module?

Suppose I create a node module called m. Later on, I decide to enhance it with Typescript typings. Luckily, the module only exports a single function, so the m.d.ts file is as follows: /// <reference path="./typings/globals/node/index.d.ts" /> decl ...

Moving SVG Module

My goal is to create a custom component that can dynamically load and display the content of an SVG file in its template. So far, I have attempted the following approach: icon.component.ts ... @Component({ selector: 'app-icon', templa ...

Launching a nested route with a specific URL in Angular 5

I've set up specific routes in my application: export const ContainerRoutes: Routes = [ { path: 'container', component: containerComponent, children: [ ...FirstRoutes, ...SecondRoutes ...

"Pairing AngularJS 2 with Vaadin for a winning combination

Good day, I'm currently following a tutorial but encountering some challenges with integrating Vaadin and Angularjs2 into my Joomla Backend project. The error message I am facing is as follows: polymer-micro.html:196 Uncaught TypeError: Cannot read ...

Angular 2 Element Selection: Dealing with Unrendered Elements

This form consists of three input fields: <div> <input *ngIf = "showInputs" #input1 (change)="onTfChnage(input2)" type="text"/> <input *ngIf = "showInputs" #input2 (change)="onTfChnage(input3)" type="text"/> <input *ngIf = "showInp ...

Invalidating Angular Guards

My goal is to have my auth guard determine access privileges using an observable that periodically toggles a boolean value. My initial approach was as follows: auth$ = interval(5000).pipe(map((n) => n % 2 === 0)); canActivate( next: ActivatedRoute ...

Consolidate multiple generic items into a single entry

In my current project, I am structuring the types for a complex javascript module. One of the requirements is to handle multiple types using generics, as shown in the snippet below: export interface ModelState< FetchListPayload, FetchListR ...