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

Doesn't work in browser

Open ajoslin103 opened this issue 2 years ago • 6 comments

Hi,

If would be great if you could release a subset of this package that only included the csvStringifier and removed the dependency on the fs package

Thanks Al;

ajoslin103 avatar Jul 28 '21 12:07 ajoslin103

Hi @ajoslin103 , sorry for my slow response. I wonder if you could just use csvStringifier. csvWriter shouldn't cause any troubles if you're not using it in browsers.

ryu1kn avatar Nov 22 '21 06:11 ryu1kn

:) slow response ok - I can’t remember what I was working on back then - I must have found a way around it

from the comment it looks like I couldn’t use csvStringifier in the browser because it had a dependency on fs which I don’t have when in the browser

it was back in july, so this might have been due to webpack 5 not auto poyfilling node modules

in any case, you can close this issue

cheers!

Al;

On Nov 22, 2021, at 1:27 AM, Ryuichi Inagaki @.***> wrote:

Hi @ajoslin103 https://github.com/ajoslin103 , sorry for my slow response. I wonder if you could just use csvStringifier. csvWriter shouldn't cause any troubles if you're not using it in browsers.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ryu1kn/csv-writer/issues/75#issuecomment-975171248, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADML5KMG24OXDKUJTAA5YTUNHPEFANCNFSM5BEJK4KA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ajoslin103 avatar Nov 22 '21 13:11 ajoslin103

Same issue. I have been using this module for a while, but recently I tried to install it with a newer node (16.14.2) / npm (8.5.0) and I get the following error:

ERROR in ./node_modules/csv-writer/dist/lib/file-writer.js 150:11-24
Module not found: Error: Can't resolve 'fs' in '[project_path]/node_modules/csv-writer/dist/lib'
  Parsed request is a module
  using description file: [project_path]/node_modules/csv-writer/package.json (relative path: ./dist/lib)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      [project_path]/node_modules/csv-writer/dist/lib/node_modules doesn't exist or is not a directory
      [project_path]/node_modules/csv-writer/dist/node_modules doesn't exist or is not a directory
      [project_path]/node_modules/csv-writer/node_modules doesn't exist or is not a directory
      [project_path]/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in [project_path]/node_modules
        single file module
          using description file: [project_path]/package.json (relative path: ./node_modules/fs)
            no extension
              [project_path]/node_modules/fs doesn't exist
            .web.mjs
              [project_path]/node_modules/fs.web.mjs doesn't exist
            .mjs
              [project_path]/node_modules/fs.mjs doesn't exist
            .web.js
              [project_path]/node_modules/fs.web.js doesn't exist
            .js
              [project_path]/node_modules/fs.js doesn't exist
            .json
              [project_path]/node_modules/fs.json doesn't exist
            .web.jsx
              [project_path]/node_modules/fs.web.jsx doesn't exist
            .jsx
              [project_path]/node_modules/fs.jsx doesn't exist
        [project_path]/node_modules/fs doesn't exist
      /media/bast/bastSSD/workspace/undoo/node_modules doesn't exist or is not a directory
      /media/bast/bastSSD/workspace/node_modules doesn't exist or is not a directory
      /media/bast/bastSSD/node_modules doesn't exist or is not a directory
      /media/bast/node_modules doesn't exist or is not a directory
      /media/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in [project_path]/node_modules
        single file module
          using description file: [project_path]/package.json (relative path: ./node_modules/fs)
            no extension
              [project_path]/node_modules/fs doesn't exist
            .web.mjs
              [project_path]/node_modules/fs.web.mjs doesn't exist
            .mjs
              [project_path]/node_modules/fs.mjs doesn't exist
            .web.js
              [project_path]/node_modules/fs.web.js doesn't exist
            .js
              [project_path]/node_modules/fs.js doesn't exist
            .json
              [project_path]/node_modules/fs.json doesn't exist
            .web.jsx
              [project_path]/node_modules/fs.web.jsx doesn't exist
            .jsx
              [project_path]/node_modules/fs.jsx doesn't exist
        [project_path]/node_modules/fs doesn't exist
      looking for modules in [project_path]/src
        single file module
          using description file: [project_path]/package.json (relative path: ./src/fs)
            no extension
              [project_path]/src/fs doesn't exist
            .web.mjs
              [project_path]/src/fs.web.mjs doesn't exist
            .mjs
              [project_path]/src/fs.mjs doesn't exist
            .web.js
              [project_path]/src/fs.web.js doesn't exist
            .js
              [project_path]/src/fs.js doesn't exist
            .json
              [project_path]/src/fs.json doesn't exist
            .web.jsx
              [project_path]/src/fs.web.jsx doesn't exist
            .jsx
              [project_path]/src/fs.jsx doesn't exist
        [project_path]/src/fs doesn't exist
 @ ./node_modules/csv-writer/dist/lib/csv-writer.js 148:20-44
 @ ./node_modules/csv-writer/dist/lib/csv-writer-factory.js 7:19-42
 @ ./node_modules/csv-writer/dist/index.js 9:27-62
 @ ./src/format/Results.js 20:0-56 709:25-51
 @ ./src/format/index.js 9:0-32 12:0-65
 @ ./src/components/Site.js 13:0-28
 @ ./src/index.js 7:0-37 10:33-37

ouroboroscoding avatar Mar 19 '22 13:03 ouroboroscoding

After some more research it seems to be related to the latest React more so than node/npm.

Apparently the issue can be resolved by adding the following to the csv-writer package.json

  "browser": {
    "fs": false
  }

If you happen to use any other file system modules those should also be added, i.e.:

  "browser": {
    "fs": false,
    "path": false,
    "os": false
  }

ouroboroscoding avatar Mar 19 '22 14:03 ouroboroscoding

@ryu1kn I have added a pull request with a fix for this issue.

https://github.com/ryu1kn/csv-writer/pull/84

ouroboroscoding avatar Mar 19 '22 17:03 ouroboroscoding

FYI, I have forked and published csv-writer-browser in order to be able to continue my development.

ouroboroscoding avatar Apr 01 '22 14:04 ouroboroscoding