Angular PapaParseService';不是由node_modules/ngx papaparse/dist/index.js导出的
我使用Angular 4,希望使用ngx papaparse来解析一些csv 我跑Angular PapaParseService';不是由node_modules/ngx papaparse/dist/index.js导出的,angular,papaparse,Angular,Papaparse,我使用Angular 4,希望使用ngx papaparse来解析一些csv 我跑 yarn add -D ngx-papaparse@1.2.5 已将其导入我的应用程序模块 import { PapaParseModule } from "ngx-papaparse"; imports: [ BrowserModule, BrowserAnimationsModule, FormsModule, HttpClientModule, PapaParseModule,
yarn add -D ngx-papaparse@1.2.5
已将其导入我的应用程序模块
import { PapaParseModule } from "ngx-papaparse";
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
HttpClientModule,
PapaParseModule,
RouterModule.forRoot(AppRoutes),
],
并在我的解析器中编写了以下代码
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);
}
}
但我在编辑时一直看到这个问题
[!] Error: 'PapaParseService' is not exported by node_modules/ngx-papaparse/dist/index.js
奇怪的是,我的Stackblitz应用程序接受ngx-papaparse@3.0.2在这个问题上没有运行,而尝试安装3.0.2会给我以下信息:
Error: Metadata version mismatch for module /usr/local/apache2/htdocs/node_modules/ngx-papaparse/ngx-papaparse.d.ts, found version 4, expected 3
在
解析器服务.ts中
文件导入为
从“ngx papaparse”导入{Papa}
然后在构造函数中
constructor(private papa: Papa) {}
代码的其余部分很好,在这些更改之后,它将完美地工作。我遇到了同样的问题,我设法解决了它 角度版本和ngx版本必须对齐。
要根据Angular的版本查找要使用的ngx papaparse的正确版本,请参考以下url:i get'/node\u modules/ngx papaparse/dist没有导出的成员“Papa”:(@Ben这里有一个使用您的代码的工作示例链接。但唯一的区别是您使用
warn
安装这个包,而我使用npm
安装它,我认为这是有效的,因为您使用的是3.0.2。在我看来,在我需要在Angular 2上使用的1.2.5上,它实际上是从“ngx papaparse”;我需要在我的服务中执行此操作。但是在编译时我仍然会遇到以下错误:错误:“PapaParseService”不是由node_modules/ngx papaparse/dist/index.js导出的