1

I'm using Angular 4 and want to use ngx-papaparse to parse some csv

I ran

yarn add -D ngx-papaparse@1.2.5

imported it in my app.module

import { PapaParseModule } from "ngx-papaparse";
  imports: [
  BrowserModule,
  BrowserAnimationsModule,
  FormsModule,
  HttpClientModule,
  PapaParseModule,
  RouterModule.forRoot(AppRoutes),
  ],

and wrote the following code in my parser

import { Injectable } from "@angular/core";
    import { PapaParseService } from "ngx-papaparse";

    @Injectable()

    export class ParserService {
      constructor(private papa: PapaParseService) {
        //
      }

      public getData(data) {
        const options = {
          complete: (results, file) => {
            console.log("Parsed: ", results, file);
          },
          // Add your options here
        };

        this.papa.parse(data, options);
      }
    }

But I keep getting this issue at compilation

[!] Error: 'PapaParseService' is not exported by node_modules/ngx-papaparse/dist/index.js

The weird thing is that my Stackblitz app accepts ngx-papaparse@3.0.2 and doesn't run in this issue, whereas trying to install 3.0.2 gives me this:

Error: Metadata version mismatch for module /usr/local/apache2/htdocs/node_modules/ngx-papaparse/ngx-papaparse.d.ts, found version 4, expected 3
Ben
  • 81
  • 1
  • 10

2 Answers2

3

in your parser-service.ts file import as

import { Papa} from "ngx-papaparse";

and then in constructor

constructor(private papa: Papa) {}

rest of the code is fine and after these changes it will work perfectly.

Farhat Zaman
  • 1,339
  • 10
  • 20
  • i get '/node_modules/ngx-papaparse/dist has no exported member "Papa"' when i do that :( – Ben Dec 18 '18 at 07:28
  • @Ben here is a link of working example by using your code. https://stackblitz.com/edit/angular-1tqdax – Farhat Zaman Dec 18 '18 at 07:42
  • but only difference is you install this package using `yarn` while i installed it using `npm` – Farhat Zaman Dec 18 '18 at 07:45
  • i think this works because you are using 3.0.2. It seems to me that on the 1.2.5 that i need to use on my Angular 2, it's actually import { PapaParseService } from "ngx-papaparse"; that i need to do in my service. However I still get the following error when compiling: Error: 'PapaParseService' is not exported by node_modules/ngx-papaparse/dist/index.js – Ben Dec 18 '18 at 07:58
1

I faced the same issue and I managed to solve it.

Angular version and ngx-papaparse versions must be aligned. To find the correct version of ngx-papaparse to use depending on your Angular's version, refer to this url: https://alberthaff.dk/projects/ngx-papaparse/docs/v4/introduction

Termos
  • 11
  • 3