Bring in Highcharts along with highcharts-more using AngularJS 1.5, TypeScript, and webpack

Currently, I am attempting to integrate Highcharts with some of its extensions, such as "highcharts-more," into a project that utilizes webpack, TypeScript, and AngularJS (version 1.5).

I have successfully installed Highcharts via npm (https://www.npmjs.com/package/highcharts). However, I am encountering difficulties when trying to import the bundled extensions.

My current solution involves setting global variables in the webpack configuration file:

plugins: [
    new webpack.ProvidePlugin({
        Highcharts: 'highcharts',
        HighchartsMore: 'highcharts/highcharts-more',
        HighchartsExporting: 'highcharts/modules/exporting'
    })
]

and manually extending Highcharts:

HighchartsMore(Highcharts);
HighchartsExporting(Highcharts);

without any direct imports. Unfortunately, TypeScript is throwing errors due to this workaround:

error TS2304: Cannot find name 'HighchartsMore'
error TS2304: Cannot find name 'HighchartsExporting'

Interestingly, there are no issues with importing just Highcharts itself using:

import * as Highcharts from 'highcharts';

As an alternative, I would prefer to cleanly import each module separately, for example:

import {HighchartsMore} from 'highcharts-more';

Any suggestions or insights on how to achieve this would be greatly appreciated.

Answer №1

If you encounter this kind of error, it may be due to missing definition files for exported variables. Highcharts extensions still rely on them - for more information on importing modules without d.ts, check out this link as the requirements might change in the future.

To resolve the issue, you will need to create a d.ts file for the extensions. Here is an example file for highcharts-more:

/// <reference path="index.d.ts" />

declare var HighchartsMore: (H: HighchartsStatic) => HighchartsStatic;

declare module "highcharts/highcharts-more" {
    export = HighchartsMore;
}

The reference path should point to the standard DefinitelyTyped Highcharts file located here. This allows for proper typing when initializing the extension:

HighchartsMore(Highcharts);

Lastly, remember to include all d.ts files either by configuring tsconfig or by specifying reference paths in your files.

Answer №2

To update your webpack configuration, you need to make the following changes:

Remove the lines below from your webpack.config.js file:

plugins: [
    new webpack.ProvidePlugin({
        Highcharts: 'highcharts',
        HighchartsMore: 'highcharts/highcharts-more',
        HighchartsExporting: 'highcharts/modules/exporting'
    })
]

Next, install the typings file for Highcharts by running the following command:

npm install --save @types/highcharts

Finally, adjust your import statements as shown below:

import * as Highcharts from 'highcharts';
import HighchartsMore = require('highcharts/highcharts-more');
HighchartsMore(Highcharts);

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

Placing JSON Reply into a Select Menu

After receiving a Json Response as follows JSON : { "json": { "response": { "servicetype": "1", "functiontype": "10011", "statuscode": "0", "statusmessage": "Success", "data": { "assignedroles": [ { ...

Leveraging aws-sdk within a TypeScript, jQuery, and webpack application

Greetings! I have a TypeScript/jQuery/Webpack application with all the latest releases, and everything seems to be functioning properly. Now, I am attempting to integrate the aws-sdk into it. I followed the same approach I used for importing other librarie ...

The issue with type checking being disrupted when importing from a TypeScript file

I have a TypeScript file containing an openapi object schema constant: export default { "title": "Draft", "description": "A new draft listing", "type": "object", "additionalProperties ...

Modify the value within the Date Selector upon explicit deletion

In my Angular Project, I have implemented a form with an input type of text that serves as a datepicker. Everything is functioning properly except for a peculiar issue that I am struggling to resolve. The problem arises when I select a date using the date ...

Receiving an error with React Proptypes when using the union type Breakpoint

Struggling to assign the correct proptype to the material-ui Breakpoint type. The breakpoint values are: export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl'; In my App.tsx file, I have the following ...

What is the best way to successfully pass the desired value to the Angular 4 controller by clicking the button?

Here is some HTML code that I am working with: <div class="btn-group" role="group" aria-label="Basic example" *ngFor="let techlist of technology"> <button type="button" class="btn btn-secondary" (click)="resList()">{{techlist.TechnologyRo ...

React throwing an error when trying to use inline fontWeight styling with Typescript

I am currently working on applying a CSS rule to a td element. const boldText = { fontWeight: 'bold' } <td style={boldText}>Content</td> Unfortunately, I am encountering the following error: [ts] Type '{ style: { fontWeig ...

Issue encountered during production mode compilation: "Vue Laravel Mix" is not a valid function

I'm working on a Laravel, VueJs, VueRouter, Vuex application that utilizes Webpack for compiling assets. Here's my package.json file: { "private": true, "scripts": { "dev": "npm run development", "development": "cross-env ...

It is impossible to declare a class attribute that has the same type as the class itself, creating a self-referencing hierarchy

My Angular model class has properties that reference the class itself: export class ItemCategory { constructor( public parentCategory?: ItemCategory, public subCategories?: ItemCategory[], public name?: string, public description?: st ...

Neglecting to set the lint parserOptions.project configuration to the project's tsconfig.json file following the migration to Angular

When upgrading from Angular 15 to Angular 16.2.x, I encountered the need to update devDependencies, specifically eslint from ~8.33.0 to ^8.39.0 After the migration, I ran into this error message: You have attempted to use a lint rule that requires the T ...

Accessing file uploads in Angular 2

<div class="fileUpload btn btn-primary"> <span>Select File</span> <input id="uploadBtn" type="file" class="upload" value="No File Chosen" #uploadBtn/> </div> <input id="uploadFile" placeholder="No File Selected" disable ...

Why do we need the TypeScript ts-jest pre-processor?

I am relatively new to TypeScript and JavaScript, so I have a question regarding the necessity of preprocessing modules like ts-jest for running Jest tests with TypeScript code. Currently, I am working on a TypeScript project in Node and everything seems t ...

When using Yeoman and Bower to scaffold a fresh Angular application, Eclipse runs out of memory

Recently, I decided to give Yoeman, Bower and Grunt a try. On two different projects, I utilized Yoeman and Bower to scaffold an Angular application. Oddly enough, Eclipse (STS 3.4.0) crashed due to memory issues both times, even though there was plenty o ...

I lost my hovering tooltip due to truncating the string, how can I bring it back in Angular?

When using an angular ngx-datatable-column, I added a hovering tooltip on mouseover. However, I noticed that the strings were too long and needed to be truncated accordingly: <span>{{ (value.length>15)? (value | slice:0:15)+'..':(value) ...

Retrieve values from a nested object using a variable in AngularJS

obj { val1 { nestedval {} } val2 { nestedval {} } } I'm having trouble accessing the nested value and assigning either val1 or val2 as a variable. I've been trying: var getVal = obj.varible.nestedval but it's not working f ...

Utilize Typescript with React to efficiently destructure and spread objects

My goal is to maintain my child components as stateless (functional components). Therefore, I am in search of an efficient way to pass down the root component's state values to its children. For example, interface IState { a: string; b: number; ...

The argument provided is a string type, which cannot be assigned to a parameter expecting an object with a 'results' property of type string

When attempting to pass the result.nativeEvent.message to another function, I am encountering the error: Argument of type 'string' is not assignable to parameter of type '{ results: string; } on onUnityMessageController(result.nativeEvent.me ...

When I apply flex to the display of .ant-steps-item-icon, the connection between the steps vanishes

I recently utilized ANTD and React to develop a customized component step style, but ran into an issue. Here is the CSS code snippet I used: /* step connector */ .ant-steps-item-title:after { border: solid rgba(65, 64, 66, 0.1) !important; } /* step * ...

How can I remove specific items from a PrimeNG PickList?

Currently, I'm working on a page where updates are made using PrimeNG PickList. The initial state of the target list is not empty, but when selected items are moved from source to target list, they are not removed from the source list as expected. Fr ...

Create a Container for Your Designs

I am faced with the challenge of developing a portal container using HTML5 and Javascript. This container will receive a variable number of widget URLs and it is responsible for loading them via Ajax in separate DIVs (not iFrames). My question is how can ...