Closed etavener closed 4 years ago
Which version did you use before? It is hard to help you with the little of information you provide. What does file
stands for? This will be categorized into question until a bug is reported.
I have the same issue, except that for me it never worked.
I am pretty new so tell me what info you need. I am using typescript btw. the example below works when we omit csvparser related code, it return the content of the file (but as one big string, obviously)
import * as CsvParser from 'csv-parse';
import {Observable, Subscriber} from "rxjs";
function parse(file:File):Observable<any>{
let fileReader = new FileReader();
let p:CsvParser.Parser= CsvParser({delimiter:","});
fileReader.readAsText(file);
return Observable.create( (observer:Subscriber<any>):void=>{
fileReader.onload = (e):void => {
let res:string=fileReader.result as string
p.write(res);
let output:any=p.read();
observer.next( output );
}
fileReader.onerror= (e):void =>{
observer.error(e)
}
})
}
here is my package.json: https://pastebin.com/9QWnDgFZ
The issue seems to be with the use of stream in browser context as explained here: https://github.com/mholt/PapaParse/issues/517
"paths": { "stream": [ "../node_modules/readable-stream" ] },
with npm install readable-stream
in tsconfig.json
solves part of the problem : the app can now load without the previous error.
Now I get this:
But probably the fix would be to do as here: https://github.com/mholt/PapaParse/pull/580
I personally use this package with webpack and I didn't yet encounter any issue. I am not familiar with angular, are you using something like webpack or browserify?
Webpack ? Browserify? I have no idea what those are... Maybe looking at my package.json helps? I'm using angular typescript with angular material, and really, my app has no fancy options yet that could interfere.
This is probably the reason then. This package is written for Node.js which has a few module a web environment doesn't have, including your errors above, the stream
module and process
. A lot of web developer use a JavaScript bundler for performance and convenience. Among other things, the bundler will ensure the dependencies which are Node.js specific are satisfied.
Instead of using the module present in the lib
folder, you should use the ones present inside lib/es5
, for exemple instead of import * as CsvParser from 'csv-parse';
, you should have something like import * as CsvParser from 'csv-parse/lib/es5';
I have just upgraded my application from Angular 5 to Angular 8. Since this was done this module seems to causing a runtime error. Previously It had been working fine.
I can confirm that without this module the app runs as expected.
When I import the npm module as follows:
I get the following console error:
Using csv-parse@4.8.8
Any solutions either long term / short term fixes would be appreciated.