Incorporating the Chartist plugin into an Angular 5 application

Currently, I am facing an issue while attempting to create a project in Angular 5 that involves utilizing chartist @types and js files of chartist plugins.

Interestingly, the files compile without any issues in Angular 4, but encounter difficulties when trying to compile or load in Angular 5.

I find myself in a state of confusion regarding the necessary steps to resolve this matter.

Encountering an error during compilation:

ERROR in error TS5055: Cannot write file '/chartist/chartist-plugin-tooltip.js' because it would overwrite the input file

In this particular scenario, I directly import files in the components as shown below:

import * as CLegend from "../../../chartist/chartist.legend";
import * as CPoints from "../../../chartist/chartist.pointlabels";
import * as CFDoughnut from '../../../chartist/chartist.fill-donut';
import * as CTooltip from '../../../chartist/chartist-plugin-tooltip';

Interestingly, this method works perfectly fine in Angular 4.

In scenarios where compilation is successful:

I have included the aforementioned files in angular-cli.json under the scripts key within an array.

  "scripts": [
    "../chartist/chartist.legend.js",
    "../chartist/chartist.pointlabels.js",
    "../chartist/chartist.fill-donut.js",
    "../chartist/chartist-plugin-tooltip.js"
  ]

I have made an attempt following this guide, which enabled a successful compilation. However, I encountered errors in JavaScript stating that Chartist.plugins is undefined.

Additionally, I have tried adding the following to my typings.d.ts:

interface Chartist {
  plugins? : any
}

as well as:

declare module 'ChartistLegend';
declare module 'ChartistPoints';
declare module 'ChartistFDoughnut';
declare module 'ChartistTooltip';

I have attempted to use both of these methods individually, but not simultaneously.

ng -v output:

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
            |___/

Angular CLI: 1.6.3
Node: 6.11.0
OS: win32 x64
Angular: 5.1.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 5.0.3
@angular/cli: 1.6.3
@angular/material-moment-adapter: 5.0.3
@angular/material: 5.0.3
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.3
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.4.2
webpack: 3.10.0

Sincerely,

PS: Please excuse any errors as my fingers are quite cold.

EDIT 1: Added information about Angular versions

Answer №1

After some experimenting, I finally figured out how to resolve the undefined plugin problem I was facing. Turns out, adding the following lines of code made all the difference:

import * as Chartist from 'chartist';
import 'chartist-plugin-tooltips';

And just like that, the issue was resolved!

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

PrismaClient is currently incompatible with this browser environment and has been optimized for use in an unknown browser when performing updates

While attempting to update a single field in my database using server-actions and tanstackQuery, I encountered the following error message: Error: PrismaClient is unable to run in this browser environment, or has been bundled for the browser (running in ...

Angular ngx-translate Feature Module failing to inherit translations from Parent Module

Currently, I am implementing lazy loading for a feature module. I have imported TranslateModule.forChild() with extend true to load feature-specific translations. In my app.module, I am importing TranslateModule.forRoot to load common translations. The i ...

Advantages of utilizing Observables instead of HTTP in Angular

As a newcomer to Angular, I am navigating the decision between utilizing rxjs/Observables versus simply using Http get/post calls. My research has indicated that Observables are most suitable for scenarios where data needs to be loaded asynchronously in a ...

Do I really need to install @angular/router as a dependency in Angular CLI even if I don't plan on using it?

After creating a new Angular CLI project, I noticed that certain dependencies in the package.json file seemed unnecessary. I wanted to remove them along with FormModules and HttpModules from imports: @angular/forms": "^4.0.0", @angular/http": "^4.0.0", @a ...

Unleashing the power of Angular 7+: Extracting data from a JSON array

As a newcomer to Angular and API integration, I am facing a challenge in fetching currency exchange rates data from the NBP Web API. The JSON file structure that I'm working with looks like: https://i.stack.imgur.com/kO0Cr.png After successfully ret ...

Encountering [Object Object] within an angular2 app

https://i.stack.imgur.com/iceKH.pngI recently created an angular2 application using ngrx/effects for handling http calls. My reference point was an application on GitHub. However, I am facing an issue where the response from the HTTP call is not displaying ...

Determine the data type of an object's key

I have a XInterface defined as: export interface XInterface { foo: (() => Foo[]) | Foo[], bar: string, baz: number } When declaring an object using this interface, I want the type of foo to be Foo[], like so: const myObj: XInterface = { ...

Why is the function not being called when declaring a variable, resulting in a type error?

click here reference: const fn1 = (arg1: { key: number, })=>{ console.log(arg1) } fn1({ key: 1 }) const data = { key: 1, a: 1, } fn1(data) fn1({ key: 1, a: 1, }) more info Assistance needed: Why is ...

incorporating my unique typographic styles into the MUI framework

I'm currently working on customizing the typography for my TypeScript Next.js project. Unfortunately, I am facing difficulties in configuring my code properly, which is causing it to not work as expected. Can someone kindly provide assistance or guida ...

What could be the reason for certain Angular modules importing successfully while others fail to do so?

I am encountering an issue with a module that I am struggling to import. Using Typescript 2.7 and Node 10 The pxl-ng-security module is showing an error in both VSCode and VS2019. When hovering over it, error 2307 is displayed. Below is the import secti ...

I am currently working on establishing a connection between Angular and MongoDB

I built a basic Angular application currently running on Local Host 4200. What is the process for saving form values and storing them in a MongoDB database? ...

Could you explain the meaning of the :host /deep/ selector?

Can you provide a simple explanation of what the :host /deep/ selector does? :host /deep/ .ui-autocomplete { width: 85%; } ...

Uncertainty surrounding the differences between SSG and SSR in the latest version of Angular

Currently, I have a small Angular 13 application hosted on GitHub Pages that I'm looking to upgrade to Angular 18 in order to take advantage of the latest features. In addition, I am considering transitioning to SSG for a better user experience while ...

Error encountered during Typescript compilation: Type 'void' cannot be assigned to type 'Item[]'

Below are my typescript functions. When I edit in vscode, the second function does not show any error message. However, upon compilation, an error is displayed for the second function: error TS2322: Type 'Promise<void>' is not assignable t ...

Methods for resolving a ViewStyle typescript issue in react native

Trying to pass a width parameter into StyleSheet is causing an error like this: <View style={styles.children(width)}>{children}</View> Here's how I'm trying to use it: const styles = StyleSheet.create({ modalContent: { flex: ...

Challenges Faced with Implementing Active Reports in Angular 9

After following all the necessary steps outlined in this website to integrate Active Reports with Angular 9 (), I encountered an error when trying to compile my app: ERROR in The target entry-point "@grapecity/activereports-angular" has missing dependen ...

Converting JQueryPromise to Promise: A step-by-step guide

In my current project, there is a code snippet that produces a JQuery promise: const jqProm = server.downloadAsync(); I am interested in integrating this promise within an async function. I was thinking of creating something similar to the C# TaskComplet ...

Is there a way to access a specific tab index in Ionic 3.20 from a child page using a function call?

Imagine having a tabs page with 3 index pages. The first index page is the home page, the second is the products page, and the third is the cart page. When navigating from the home page to the search page, there is a button that you want to click in orde ...

Discover how to access and manipulate JSON files in an Angular application using

Currently, I am diving into learning TypeScript with Angular and I'm interested in reading a JSON file. The structure of my JSON file is as follows: { "nb": "7", "extport": "1176",, "REQ_EMAIL": ...

How can we update the information in the initial observable using data from a separate observable, taking into consideration specific conditions in Angular with RxJS?

Encountered a scenario where I need to fetch data from an API (e.g. cars via getCars()) that returns Observables and then get additional data by car model (e.g. features via getFeatures(model)) in order to replace the features data for each car. In relati ...