0

this is my app module file all bits and pieces are at the same place as mentioned in document

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import * as PlotlyJS from 'plotly.js-dist';
import { PlotlyModule } from 'angular-plotly.js';

PlotlyModule.plotlyjs = PlotlyJS;

import { AppComponent } from './app.component';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    PlotlyModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

below is the error i am getting in cosole

main.ts:12 Error: Invalid PlotlyJS object. Please check https://github.com/plotly/angular-plotly.js#quick-start to see how to add PlotlyJS to your project.
    at new PlotlyModule (angular-plotly.js.js:520)
    at Object.PlotlyModule_Factory [as factory] (angular-plotly.js.js:529)
    at R3Injector.hydrate (core.js:11416)
    at R3Injector.get (core.js:11236)
    at core.js:11273
    at Set.forEach (<anonymous>)
    at R3Injector._resolveInjectorDefTypes (core.js:11273)
    at new NgModuleRef$1 (core.js:25336)
    at NgModuleFactory$1.create (core.js:25390)
    at core.js:29276
2
  • Did you also update the plotly libraries to their latest versions? Commented Jul 1, 2021 at 18:51
  • Yes i did update Commented Jul 1, 2021 at 19:39

2 Answers 2

1

I checked the documentation at https://www.npmjs.com/package/angular-plotly.js?activeTab=readme. Looks like the import varies for PlotlyJS:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import * as PlotlyJS from 'plotly.js/dist/plotly.js'; // this line
import { PlotlyModule } from 'angular-plotly.js';

PlotlyModule.plotlyjs = PlotlyJS;

@NgModule({
    imports: [CommonModule, PlotlyModule],
    ...
})
export class AppModule { }
Sign up to request clarification or add additional context in comments.

1 Comment

I tried this too but its also giving same error
0
$ npm install angular-plotly.js plotly.js-dist-min --save

$ npm install @types/plotly.js-dist-min --save-dev

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import * as PlotlyJS from 'plotly.js-dist-min';
import { PlotlyModule } from 'angular-plotly.js';

PlotlyModule.plotlyjs = PlotlyJS;

@NgModule({
    imports: [CommonModule, PlotlyModule],
    ...
})
export class AppModule { }

Add following piece to angular.json. This should resolve the issue.

{
    "build": {
        "builder": "@angular-devkit/build-angular:browser",
        "options": {
            "scripts": [
                "node_modules/plotly.js-dist-min/plotly.min.js"
            ]
        }
    }
}

1 Comment

Please explain a little more about how this line could fix the issue, it didn't work for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.