rars / ng2csv

Angular service for saving data to CSV file.
MIT License
6 stars 2 forks source link

saveAs is not a function #11

Closed cherrera50 closed 1 year ago

cherrera50 commented 5 years ago

Hello:

I would like to use this library for a specific part of my project. When I tried to follow the example given in the documentation, I got this error:

TypeError: file_saver_1.saveAs is not a function

The code in the download function is this:

 public download(): void {
    try {
      this.ng2Csv.download([
        {
          id: 1,
          name: 'Alice'
        },
        {
          id: 2,
          name: 'Bob'
        }
      ],
        'names.csv');
    } catch (e) {
      alert(e);
    }
  }
As additional data. I got a similar error using the file-saver library in direct way, but I could find a solution using this code in my component:
declare var saveAs: any; 
Instead of this:
import { saveAs } from 'file-saver';
In this ocation, the code of the download function is this:
public download(): void {
        try {
          let file = new Blob(['hello world'], { type: 'text/csv;charset=utf-8' });
          saveAs(file, ''helloworld'.csv');
        } catch (e) {
          alert(e);
        }
And you be able to download the helloword.csv file generated. Thanks for your help. Regards
rars commented 5 years ago

Thanks @cherrera50 for filing this issue. Could you post your package.json dependencies so I know which versions of libraries you are using or list these please?

cherrera50 commented 5 years ago

Ok,

This is my package.json configuration:

{
  "name": "angular-seed",
  "version": "0.0.0",
  "description": "Modular starter project for Angular 2 (and beyond) with statically typed build and AoT compilation",
  "repository": {
    "url": "https://github.com/mgechev/angular-seed"
  },
  "scripts": {
    "build.dev": "gulp build.dev --color --env-config dev",
    "build.dev.watch": "gulp build.dev.watch --color",
    "build.e2e": "gulp build.e2e --color",
    "build.prod": "gulp build.prod --color --env-config prod --build-type prod",
    "build.prod.exp": "gulp build.prod.aot --color --env-config prod --build-type prod",
    "build.prod.rollup.aot": "gulp build.prod.rollup.aot --color --env-config prod --build-type prod",
    "build.prod.aot": "gulp build.prod.aot --color --env-config prod --build-type prod",
    "build.test": "gulp build.test --color",
    "test.watch": "gulp test.watch --color",
    "generate.manifest": "gulp generate.manifest --color",
    "e2e": "protractor",
    "e2e.live": "protractor --elementExplorer",
    "gulp": "gulp",
    "i18n": "ng-xi18n && gulp clean.i18n",
    "lint": "gulp tslint",
    "karma": "karma",
    "karma.start": "karma start",
    "postinstall": "gulp check.versions && gulp build.bundle.rxjs && npm prune && gulp webdriver && gulp print.banner",
    "reinstall": "npm cache clean && npm install",
    "serve.coverage": "gulp serve.coverage --color",
    "serve.dev": "gulp serve.dev --color --env-config dev",
    "serve.e2e": "gulp serve.e2e --color",
    "serve.prod": "gulp serve.prod --color --env-config prod --build-type prod",
    "serve.prod.aot": "gulp serve.prod.aot --color --env-config prod --build-type prod",
    "serve.prod.exp": "gulp serve.prod.aot --color --env-config prod --build-type prod",
    "serve.prod.rollup.aot": "gulp serve.prod.rollup.aot --color --env-config prod --build-type prod",
    "start": "gulp serve.dev --color",
    "start.deving": "gulp start.deving --color",
    "tasks.list": "gulp --tasks-simple --color",
    "test": "gulp test --color",
    "e2e.ci": "gulp build.prod --color && gulp build.e2e --color && gulp e2e --color",
    "tests.all": "npm test && npm run e2e.ci",
    "webdriver-start": "webdriver-manager start",
    "webdriver-update": "webdriver-manager update",
    "compodoc": "node_modules/.bin/compodoc -p src/client/tsconfig.json",
    "serve.compodoc": "node_modules/.bin/compodoc -s"
  },
  "author": "Minko Gechev ",
  "license": "MIT",
  "devDependencies": {
    "@angular/compiler-cli": "~2.4.0",
    "@angular/platform-server": "~2.4.0",
    "@types/async": "^2.0.32",
    "@types/browser-sync": "^0.0.34",
    "@types/express": "^4.0.33",
    "@types/express-serve-static-core": "4.0.49",
    "@types/file-saver": "^2.0.1",
    "@types/gulp": "^3.8.32",
    "@types/gulp-filter": "^3.0.29",
    "@types/gulp-load-plugins": "^0.0.28",
    "@types/gulp-protractor": "^1.0.29",
    "@types/gulp-sass": "^0.0.29",
    "@types/gulp-util": "^3.0.29",
    "@types/jasmine": "2.5.41",
    "@types/node": "^6.0.45",
    "@types/rimraf": "0.0.28",
    "@types/run-sequence": "^0.0.28",
    "@types/selenium-webdriver": "^2.53.39",
    "@types/systemjs": "^0.19.31",
    "@types/yargs": "^6.5.0",
    "@types/zone.js": "^0.0.27",
    "async": "^2.1.1",
    "autoprefixer": "^6.5.1",
    "browser-sync": "^2.26.5",
    "codelyzer": "^2.0.1",
    "compodoc": "0.0.41",
    "connect-history-api-fallback": "^1.3.0",
    "cssnano": "^3.7.7",
    "deep-extend": "^0.6.0",
    "event-stream": "^3.3.4",
    "express": "^4.16.4",
    "express-history-api-fallback": "^2.0.0",
    "gulp": "^3.9.1",
    "gulp-cached": "^1.1.0",
    "gulp-concat": "^2.6.0",
    "gulp-concat-css": "^2.3.0",
    "gulp-filter": "^4.0.0",
    "gulp-inject": "^4.1.0",
    "gulp-inline-ng2-template": "^4.0.0",
    "gulp-load-plugins": "^1.6.0",
    "gulp-plumber": "~1.1.0",
    "gulp-postcss": "^6.2.0",
    "gulp-progeny": "^0.3.1",
    "gulp-protractor": "^3.0.0",
    "gulp-rename": "^1.2.2",
    "gulp-replace": "^0.5.4",
    "gulp-sass": "^3.0.0",
    "gulp-sourcemaps": "2.2.0",
    "gulp-template": "^4.0.0",
    "gulp-tslint": "7.0.1",
    "gulp-typescript": "^3.0.2",
    "gulp-uglify": "^2.0.0",
    "gulp-util": "^3.0.7",
    "gulp-watch": "^4.3.10",
    "is-ci": "^1.0.9",
    "isstream": "^0.1.2",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "^3.0.0",
    "karma": "~1.3.0",
    "karma-chrome-launcher": "~2.0.0",
    "karma-coverage": "^1.1.2",
    "karma-jasmine": "~1.1.0",
    "karma-mocha-reporter": "^2.2.0",
    "karma-remap-istanbul": "^0.6.0",
    "merge-stream": "^1.0.0",
    "minimatch": "^3.0.3",
    "open": "0.0.5",
    "protractor": "^4.0.14",
    "remap-istanbul": "^0.8.4",
    "rimraf": "^2.5.4",
    "rollup": "^0.41.4",
    "rollup-plugin-commonjs": "^7.0.0",
    "rollup-plugin-includepaths": "0.2.1",
    "rollup-plugin-node-resolve": "^2.0.0",
    "run-sequence": "^1.2.2",
    "semver": "^5.3.0",
    "serve-static": "^1.11.1",
    "slash": "~1.0.0",
    "supports-color": "^3.1.2",
    "systemjs-builder": "^0.16.13",
    "tildify": "^1.2.0",
    "traceur": "^0.0.111",
    "ts-node": "^2.0.0",
    "tslint": "^4.3.0",
    "typescript": "~2.0.9",
    "walk": "^2.3.9",
    "yargs": "^6.0.0"
  },
  "dependencies": {
    "@angular/common": "~2.4.0",
    "@angular/compiler": "~2.4.0",
    "@angular/core": "~2.4.0",
    "@angular/forms": "~2.4.0",
    "@angular/http": "~2.4.0",
    "@angular/platform-browser": "~2.4.0",
    "@angular/platform-browser-dynamic": "~2.4.0",
    "@angular/router": "~3.4.1",
    "angular2-qrcode": "^2.0.1",
    "angular2-websocket": "^0.9.5",
    "core-js": "^2.4.1",
    "d3": "^4.3.0",
    "dragula": "^3.7.2",
    "file-saver": "^2.0.2",
    "font-awesome": "^4.7.0",
    "intl": "^1.2.5",
    "jquery": "^3.4.1",
    "jquery-ui-browserify": "^1.11.0-pre-seelio",
    "natives": "^1.1.6",
    "ng-socket-io": "^0.1.10",
    "ng2-dragula": "^1.3.0",
    "ng2-google-charts": "^3.4.0",
    "ng2csv": "^0.4.0",
    "qrious": "^4.0.2",
    "reflect-metadata": "^0.1.8",
    "rxjs": "~5.1.1",
    "systemjs": "0.19.41",
    "tinymce": "^4.4.3",
    "zone.js": "^0.7.2"
  }
}
rars commented 5 years ago

I'm having trouble trying to reproduce something similar to this. I tried checking out tag 2.1.2 https://github.com/mgechev/angular-seed/tree/2.1.2 and building on a NodeJS 6 install but there are some errors on the npm install.

What version of NodeJS are you using? If you could help me produce a smaller reproduction of the issue I could offer some further help.

rars commented 1 year ago

Closing since there's been no response since my last message and I can't repro. Let me know if you think there's still an issue.