C2FO / fast-csv

CSV parser and formatter for node
http://c2fo.github.io/fast-csv
MIT License
1.65k stars 210 forks source link

[BUG] Module not found: Error: Can't resolve 'fs' #278

Closed swkang73 closed 4 years ago

swkang73 commented 5 years ago

I'm trying to use fast-csv in my Angular Cli 8 project, but it's getting the following error:

ERROR in ./node_modules/fast-csv/build/src/formatter/index.js
Module not found: Error: Can't resolve 'fs' in '[my project directory]/node_modules/fast-csv/build/src/formatter'
ERROR in ./node_modules/fast-csv/build/src/parser/index.js
Module not found: Error: Can't resolve 'fs' in '[my project directory]/node_modules/fast-csv/build/src/parser'

I've checked "@types/node": "^12.7.2" is included as one of the dependencies in package.json.

The tsconfig.json looks like this:

{
  "compilerOptions": {
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "declaration": true,
    "forceConsistentCasingInFileNames": true,
    "lib": ["es2016"],
    "module": "commonjs",
    "noEmitOnError": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "pretty": true,
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "typeRoots": ["./node_modules/@types"],
    "rootDir": ".",
    "outDir": "build"
  },
   "exclude": [
     "node_modules"
   ],
  "include": [
    "src/**/*.ts",
    "test/**/*.ts"
  ]
}

Any idea why the 'fs' import isn't working?

doug-martin commented 4 years ago

@swkang73 I tried an example with your tsconfig and my code built without errors. If you could provide a small example (gist or repo) the demonstrates the problem I can try to help diagnose the problem.

JiangHongTiao commented 4 years ago

Hi @doug-martin , I'm experiencing the same issue with Angular 9. I was following this advice: https://stackoverflow.com/a/50212007/3928593 and added into fast-csv library package.json file with following lines:

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

and the error has disappeared. However I'm not able to use the library, it throws an error in console then:

Uncaught TypeError: Class extends value undefined is not a constructor or null
    at Object.../../../node_modules/@fast-csv/format/build/src/CsvFormatterStream.js (vendor.js:111114)
    at __webpack_require__ (runtime.js:80)
    at Object.../../../node_modules/@fast-csv/format/build/src/index.js (vendor.js:111518)
    at __webpack_require__ (runtime.js:80)
    at Module../pages/search.component.ts (main.js:19874)
    at __webpack_require__ (runtime.js:80)
    at Module../app.routing.module.ts (main.js:1953)
    at __webpack_require__ (runtime.js:80)
    at Module../app.module.ts (main.js:1824)
    at __webpack_require__ (runtime.js:80)