node-csv icon indicating copy to clipboard operation
node-csv copied to clipboard

angular stream import

Open ldiaz opened this issue 4 years ago • 2 comments

When using some of the libraries, I used 'csv-stringify' (Which is Awesome, thanks for the project), inside an angular project I got this error while building using ng build:

Module not found: Error: Can't resolve 'stream' in '{project-path}/node_modules/csv-stringify/lib'
resolve 'stream' in '{project-path}/node_modules/csv-stringify/lib'
  Parsed request is a module
  using description file: {project-path}/node_modules/csv-stringify/package.json (relative path: ./lib)
    Field 'browser' doesn't contain a valid alias configuration
...

I think the API is really awesome and loved it while using it. That's why I think the library should add some kind of notice or warning to non-nodejs execution environments like while using angular, just to clarify that It won't work by default or out of the box as brower environments doesn't implement the stream library (which nodejs by default does.). Also offer a simple fix which is:

Add the dependency stream-browserify node module using "npm install stream-browserify"

Override the path mapping in the tsconfig.json:

"compilerOptions": {
      "paths": {
         ...
        "stream": ["node_modules/stream-browserify"],
      }

This same issue was reported long ago in the old repo

ldiaz avatar Aug 05 '21 22:08 ldiaz

This shall be much better documented, but you can use the browser version of the package. It is vanilla js and there is a demo.

wdavidw avatar Aug 05 '21 22:08 wdavidw

If you find the time, would you like to contribute to a minimalist project example with angular. You are right that few people came for help in the past regarding this issue.

wdavidw avatar Aug 06 '21 06:08 wdavidw