juanjoDiaz / json2csv

Flexible conversion between JSON and CSV
https://juanjodiaz.github.io/json2csv/
MIT License
296 stars 32 forks source link

Update to @json2csv app no longer builds on old angular/typescript versions #36

Closed michelliebel closed 1 year ago

michelliebel commented 1 year ago

I have been using the old version of json2csv, and am updating to the new @json2csv/node version for the AsyncStream. After installing one or more of the components (@json2csv/plainjs, @json2csv/node, @json2csv/formatters, etc), my application no longer builds successfully.

Errors in terminal:

Error: node_modules/@json2csv/formatters/src/index.ts:3:29 - error TS2300: Duplicate identifier 'type'.

3 export { default as number, type NumberFormatterOptions } from './number.js';


Error: node_modules/@json2csv/formatters/src/index.ts:3:29 - error TS2300: Duplicate identifier 'type'.

3 export { default as number, type NumberFormatterOptions } from './number.js';

Error: node_modules/@json2csv/formatters/src/index.ts:3:29 - error TS2614: Module '"./number.js"' has no exported member 'type'. Did you mean to use 'import type from "./number.js"' instead?

3 export { default as number, type NumberFormatterOptions } from './number.js';


Error: node_modules/@json2csv/formatters/src/index.ts:3:34 - error TS1005: ',' expected.

3 export { default as number, type NumberFormatterOptions } from './number.js';

Error: node_modules/@json2csv/formatters/src/index.ts:4:29 - error TS2300: Duplicate identifier 'type'.

4 export { default as string, type StringFormatterOptions } from './string.js';


Error: node_modules/@json2csv/formatters/src/index.ts:4:29 - error TS2614: Module '"./string.js"' has no exported member 'type'. Did you mean to use 'import type from "./string.js"' instead?

4 export { default as string, type StringFormatterOptions } from './string.js';
  [91m                            ~~~~

Error: node_modules/@json2csv/formatters/src/index.ts:4:34 - error TS1005: ',' expected.

4 export { default as string, type StringFormatterOptions } from './string.js';

Error: node_modules/@json2csv/formatters/src/index.ts:7:3 - error TS2300: Duplicate identifier 'type'.

7 type StringFQuoteOnlyIfNecesaryFormatterOptions,


Error: node_modules/@json2csv/formatters/src/index.ts:7:3 - error TS2614: Module '"./stringQuoteOnlyIfNecessary.js"' has no exported member 'type'. Did you mean to use 'import type from "./stringQuoteOnlyIfNecessary.js"' instead?

7   type StringFQuoteOnlyIfNecesaryFormatterOptions,

Error: node_modules/@json2csv/formatters/src/index.ts:7:8 - error TS1005: ',' expected.

7 type StringFQuoteOnlyIfNecesaryFormatterOptions,


Error: node_modules/@json2csv/formatters/src/stringQuoteOnlyIfNecessary.ts:3:3 - error TS2614: Module '"./string.js"' has no exported member 'type'. Did you mean to use 'import type from "./string.js"' instead?

3   type StringFormatterOptions,

Error: node_modules/@json2csv/formatters/src/stringQuoteOnlyIfNecessary.ts:3:3 - error TS6133: 'type' is declared but its value is never read.

3 type StringFormatterOptions,


Error: node_modules/@json2csv/formatters/src/stringQuoteOnlyIfNecessary.ts:3:8 - error TS1005: ',' expected.

3   type StringFormatterOptions,

Error: node_modules/@json2csv/node/dist/mjs/AsyncParser.d.ts:2:25 - error TS1005: ',' expected.

2 import { Readable, type TransformOptions } from 'stream';


Error: node_modules/@json2csv/node/dist/mjs/Transform.d.ts:3:26 - error TS1005: ',' expected.

3 import { Transform, type TransformOptions, type TransformCallback } from 'stream';

Error: node_modules/@json2csv/node/dist/mjs/Transform.d.ts:3:49 - error TS1005: ',' expected.

3 import { Transform, type TransformOptions, type TransformCallback } from 'stream';


Error: node_modules/@json2csv/node/dist/mjs/Transform.d.ts:4:15 - error TS1005: ',' expected.

4 import { type ParserOptions, type StreamParserOptions } from '@json2csv/plainjs';

Error: node_modules/@json2csv/node/dist/mjs/Transform.d.ts:4:35 - error TS1005: ',' expected.

4 import { type ParserOptions, type StreamParserOptions } from '@json2csv/plainjs';


Error: node_modules/@json2csv/plainjs/dist/mjs/BaseParser.d.ts:1:15 - error TS1005: ',' expected.

1 import { type Formatter } from '@json2csv/formatters';

Error: node_modules/@json2csv/plainjs/dist/mjs/Parser.d.ts:1:29 - error TS1005: ',' expected.

1 import JSON2CSVBase, { type Json2CSVBaseOptions } from './BaseParser.js';


Error: node_modules/@json2csv/plainjs/dist/mjs/StreamParser.d.ts:2:29 - error TS1005: ',' expected.

2 import JSON2CSVBase, { type Json2CSVBaseOptions, type NormalizedJson2CSVBaseOptions } from './BaseParser.js';

Error: node_modules/@json2csv/plainjs/dist/mjs/StreamParser.d.ts:2:55 - error TS1005: ',' expected.

2 import JSON2CSVBase, { type Json2CSVBaseOptions, type NormalizedJson2CSVBaseOptions } from './BaseParser.js';


Error: node_modules/@json2csv/plainjs/dist/mjs/index.d.ts:1:38 - error TS1005: ',' expected.

1 export { default as BaseParser, type FieldValueGetterInfo, type FieldValueGetterFnWithoutField, type FieldValueGetterFnWithField, type FieldInfo, FormatterTypes, type FormattersOptions, } from './BaseParser.js';

Error: node_modules/@json2csv/plainjs/dist/mjs/index.d.ts:1:65 - error TS1005: ',' expected.

1 export { default as BaseParser, type FieldValueGetterInfo, type FieldValueGetterFnWithoutField, type FieldValueGetterFnWithField, type FieldInfo, FormatterTypes, type FormattersOptions, } from './BaseParser.js';


Error: node_modules/@json2csv/plainjs/dist/mjs/index.d.ts:1:102 - error TS1005: ',' expected.

1 export { default as BaseParser, type FieldValueGetterInfo, type FieldValueGetterFnWithoutField, type FieldValueGetterFnWithField, type FieldInfo, FormatterTypes, type FormattersOptions, } from './BaseParser.js';

Error: node_modules/@json2csv/plainjs/dist/mjs/index.d.ts:1:136 - error TS1005: ',' expected.

1 export { default as BaseParser, type FieldValueGetterInfo, type FieldValueGetterFnWithoutField, type FieldValueGetterFnWithField, type FieldInfo, FormatterTypes, type FormattersOptions, } from './BaseParser.js';


Error: node_modules/@json2csv/plainjs/dist/mjs/index.d.ts:1:168 - error TS1005: ',' expected.

1 export { default as BaseParser, type FieldValueGetterInfo, type FieldValueGetterFnWithoutField, type FieldValueGetterFnWithField, type FieldInfo, FormatterTypes, type FormattersOptions, } from './BaseParser.js';

Error: node_modules/@json2csv/plainjs/dist/mjs/index.d.ts:2:34 - error TS1005: ',' expected.

2 export { default as Parser, type ParserOptions } from './Parser.js';


Error: node_modules/@json2csv/plainjs/dist/mjs/index.d.ts:3:40 - error TS1005: ',' expected.

3 export { default as StreamParser, type StreamParserOptions, } from './StreamParser.js';

Error: node_modules/@streamparser/json/dist/mjs/index.d.ts:1:38 - error TS1005: ',' expected.

1 export { default as JSONParser, type JSONParserOptions } from "./jsonparser.js";


Error: node_modules/@streamparser/json/dist/mjs/index.d.ts:2:37 - error TS1005: ',' expected.

2 export { default as Tokenizer, type TokenizerOptions, TokenizerError, } from "./tokenizer.js";

Error: node_modules/@streamparser/json/dist/mjs/index.d.ts:3:39 - error TS1005: ',' expected.

3 export { default as TokenParser, type TokenParserOptions, TokenParserError, } from "./tokenparser.js";


Error: node_modules/@streamparser/json/dist/mjs/index.d.ts:8:32 - error TS1005: ',' expected.

8 export { TokenParserMode, type StackElement, } from "./utils/types/stackElement.js";

Error: node_modules/@streamparser/json/dist/mjs/jsonparser.d.ts:1:15 - error TS1005: ',' expected.

1 import { type TokenizerOptions } from "./tokenizer.js";


Error: node_modules/@streamparser/json/dist/mjs/jsonparser.d.ts:2:15 - error TS1005: ',' expected.

2 import { type TokenParserOptions } from "./tokenparser.js";

My code:

package.json: "@json2csv/node": "7.0.1",

component.ts:

import { AsyncParser } from '@json2csv/node';

   async download(data, view) {
    const json2csvParser = new AsyncParser();
    const csv = await json2csvParser.parse(data).promise();

    console.log('csv', csv);
  }

tsconfig.json updates to account for webpack changes:

  "compilerOptions": {
    "module": "es2020",
    "moduleResolution": "node",
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "paths" : {
      "crypto": ["node_modules/crypto-browserify"],
      "stream": ["node_modules/stream-browserify"],
      "assert": ["node_modules/assert"],
      "http": ["node_modules/stream-http"],
      "https": ["node_modules/https-browserify"],
      "os": ["node_modules/os-browserify"],
    },
    "skipLibCheck": true,
    "maxNodeModuleJsDepth": 2,

angular.json edits to account for webpack changes:

      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
                   "allowedCommonJsDependencies": ["crypto", "stream", "assert", "http", "https", "os"]

Prior to updating to this new package, the app would build correctly. If I remove the package from the package.json, and run npm install, the app builds. So I am sure it is the package introducing the breaking change. What other config setup do I need for this package to not stop my app from building?

Angular ^12.2.16 Typescript 4.3.5

Thanks!

juanjoDiaz commented 1 year ago

Hi @michelliebel,

A few things have changed. The library broke into modules in v6 and moved to Typescript since v7. Also since v6 AsyncParser API changed a bit.

It's weird that your build system is trying to build @json2csv when it's already prebuilt and includes typings. So you definitely shouldn't be rebuilding it.

Your issue seems related to your Angular version and your Typescript version based on a few public issues that I found:

Also, if you are using this on the frontend, I recommend that you use the whatwg module and the standard fetch so you don't need to polyfill stream or http/https. Or even the plainjs module.