0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Angularでcsv-parseを使う方法

Posted at

検証環境

  • Angular(12.0.5)
  • csv-parse(4.14.3)

原因

  1. csv-parsestreamというパッケージが必要なのですが、これはnode環境でのみビルドインで利用できるもので、ブラウザ環境で使うには少し工夫をする必要がある

  2. グローバル変数global, Buffer, processを定義する必要がある

というのが原因でした

なのでこれらに対処していきます

対応

必要なパッケージのインストール

$ npm i process util stream-browserify

Angular12以外のバージョンなら依存関係の中で上記のパッケージがインストールされていることがあるのでpackage-lock.jsonを確認してインストールされていれば、再度インストールする必要はない

1への対応

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

2への対応

pollyfills.ts
 (window as any).global = window;

 (window as any).Buffer = (window as any).Buffer || require('buffer').Buffer;

 global.process = require('process');

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?