Unable to locate the identifier 'Annotorious'

Currently utilizing NextJS with TypeScript The following script has been added:

<Head><link href="/css/bindingbox.min.css" rel="stylesheet"></link><script async type="text/javascript" src="/scripts/annotorious.min.js"></script></Head>

Upon trying to call:

 useEffect(()=>{
    setTimeout(() => {
        var anno = Annotorious.init({
            image: "raven_cafe",
            readOnly: true,
          });
          anno.loadAnnotations('/scripts/annotations.w3c.json');
          //disable displaying the binding box when selected on the image
          anno.on('selectAnnotation', function(data) {
            let element = document.querySelector(`g[data-id="`+data.id+`"]`);
            element.classList.remove('selected');
          });
    }, 100);
  },[]);

An error in TypeScript is raised: "Cannot find name 'Annotorious'" How can this error be resolved?

Answer №1

Although I haven't had much experience with NextJS, it seems like it primarily renders static pages. This could be why the issue lies in how NextJS transforms the output during the rendering process.

When importing via the script tag, Annotorious becomes a global variable: window.Annotorious, so additional precautions may be necessary to ensure compatibility with NextJS.

One potential solution can be found here: https://medium.com/swlh/how-to-use-a-library-in-next-js-that-wants-window-whatever-96c738263d67

The key factor appears to be the dynamic import feature that ensures the Annotorious code only executes in the browser and remains untouched during server-side rendering.

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

Guide to setting up react-styleguidist, developing with Create React App, using Typescript, incorporating Material UI, and including

Struggling to configure react-styleguidist (RSG) with Create React App 3 (CRA), Typescript, Material UI, and styled-components. Currently encountering an error: ./node_modules/react-styleguidist/lib/client/rsg-components/ReactExample/ReactExample.js Modul ...

Angular2 display user's activity status on every individual page

How can I implement visitor status tracking for every page in angular2? I have a jwt based authentication system in place that is working correctly, but now I need to ensure that the visitor's login status is checked on each route. Here is an example ...

Optimal method for accessing params and queryParams in Angular 2

Seeking insights on how to craft a route with information stored in its URL parameters. Here's an example of my route (app.routes.ts): {path: 'results/:id', component: MyResultsComponent}, How I navigate to the route : goToResultsPage(qu ...

Sending data between components in Next.js layout.tsx

Trying to figure out how to pass properties between a page and a layout in Next.js has got me scratching my head. The situation I'm facing is as follows: I've got a standard Material UI stepper component (you can find it here: link) in my layou ...

What is the best approach to re-establish a websocket connection in TypeScript?

Encountering an issue when trying to add a "retry()" method: ERROR in src/app/films.service.ts(28,20): error TS2339: Property 'retry' does not exist on type 'WebSocketSubject'. this.wsSubject.retry().subscribe( (msg) => this. ...

updating a property value with retrieved data from an API before sending it to a nested component within an Angular application

Within a parent component, I am receiving data from an API, which is an Object with various properties. The specific property I want to pass to a child component is called "structure". Using Renderer2, I aim to add a class based on the value of this "struc ...

Having difficulty in utilizing localStorage to update the state

I've attempted to log back in using the stored credentials, however it's not working despite trying everything. The dispatch function is functioning properly with the form, but not when accessing localStorage. App.tsx : useEffect(() => { ...

What is the proper syntax for defining an object property as a function?

Could someone help me find the specific location in the documentation where I can learn about the syntax of the line testMessage: (): string => {? Shouldn't it be more like testMessage: () => string;? Why are they not the same? export default { ...

Nodemailer fails to display an error message when the email is not successfully sent

I am currently working on implementing nodemailer for sending emails. However, I noticed that if the email address in the "to" field is incorrect, the email is not sent as expected. The issue is that there is no error displayed and the function still resol ...

The specified type '() => { body: string; status: number; }' cannot be assigned to a Svelte type

Attempting to create a simple API endpoint in Svelte using RequestHandler from the index.json.ts file import type { RequestHandler } from '@sveltejs/kit' export const get: RequestHandler = () => { return{ body:'Hello from api ...

What is the best way to have a variable adjust each time a coin is inserted until it reaches a specific value?

I have developed a unique coin box that recognizes the value of each coin inserted. Users can now pay for a service that costs 2.0 € by inserting coins of various denominations such as 2.0 €, 1.0 €, 0.50 €, 0.20 €, and 0.10 €. In my react-nati ...

When trying to attach a volume from a local directory to a next.js container, a TypeError occurs stating that Object(...) is not a function

Currently, I am attempting to connect a local volume directory for Next.js/React's hot reload feature during development. The configuration in my docker-compose.development.yml file is as follows: services: web: command: next dev volumes: ...

Is it possible to implement the new Next.js middleware in a custom hosting environment?

Currently, I am working on an application using Next.js specifically for user authentication via JWT's and then redirecting them to our main web application. Previously, before the release of version 12 of Next.js, I utilized next-connect to execute a ...

What methods can be employed to maintain the integrity of tuple element labels?

Context In an attempt to enhance code readability and maintainability, I am exploring the replacement of a complex overloaded function with rest parameters using labeled tuple elements. Original snippet Here's a simplified version of the existing o ...

Finding the correct placement for importing 'reflect-metadata' in Next.js version 14.1.0

I am currently integrating tsyringe for dependency injection in my Next.js 14.1.0 application using the new App Router. However, I am facing an issue with its functionality when adding import 'reflect-metadata'; at the beginning of my Root Layout ...

Efficiently search and filter items across multiple tabs using a single search bar in the Ionic 2

I am currently working on implementing a single search bar that can filter lists in 2 different tabs within Ionic 2. The search bar is functional, and I have a method for filtering through objects. However, my goal is to allow users to select different tab ...

How come the hover effect is not functioning properly following the addition of padding to

I have set a padding top of 120px, but for some reason the hover effect is not working properly. Can anyone help me troubleshoot this issue? Here is the code snippet: 'use client'; // eslint-disable-next-line no-unused-vars import React, { useSta ...

Tips for utilizing playFromPositionAsync method with expo-av Video in React Native

While working with the Video Expo component, I came across a prop called playFromPositionAsync. In the Video.d.ts file, it is defined like this: export default class Video extends React.Component<VideoProps, VideoState> implements Playback { ... ...

Tips for correctly sending headers with SWR requests?

I've made the decision to transition the majority of my API functions to SWR because of its enhanced capabilities! Issue at Hand However, I'm encountering a major problem trying to pass headers properly into SWR. Despite consulting the documenta ...

Running out of memory due to inefficient mark-compacting processes nearing the heap limit in Angular 8 allocation

A significant portion of the modules are built, with only one active in progress. The process is located at ...\src\index.js??extracted!D:\Clients\app\node_modules\sass-loader\lib\loader.js??ref--15-3!D:\src&bso ...