ryu1kn / csv-writer

Convert objects/arrays into a CSV string or write them into a CSV file
https://www.npmjs.com/package/csv-writer
MIT License
246 stars 39 forks source link

Build error when using with pnpm and nestjs #92

Open rajivkr opened 1 year ago

rajivkr commented 1 year ago

Hello, I am getting this error, when I building my nestjs application using pnpm.

`node_modules/.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/index.ts:11:14 - error TS2742: The inferred type of 'createArrayCsvStringifier' cannot be named without a reference to '.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/lib/csv-stringifiers/array'. This is likely not portable. A type annotation is necessary.

11 export const createArrayCsvStringifier = (params: ArrayCsvStringifierParams) =>

node_modules/.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/index.ts:14:14 - error TS2742: The inferred type of 'createObjectCsvStringifier' cannot be named without a reference to '.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/lib/csv-stringifiers/object'. This is likely not portable. A type annotation is necessary.

14 export const createObjectCsvStringifier = (params: ObjectCsvStringifierParams) =>

node_modules/.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/index.ts:17:14 - error TS2742: The inferred type of 'createArrayCsvWriter' cannot be named without a reference to '.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/lib/csv-writer'. This is likely not portable. A type annotation is necessary.

17 export const createArrayCsvWriter = (params: ArrayCsvWriterParams) =>

node_modules/.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/index.ts:20:14 - error TS2742: The inferred type of 'createObjectCsvWriter' cannot be named without a reference to '.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/lib/csv-writer'. This is likely not portable. A type annotation is necessary.

20 export const createObjectCsvWriter = (params: ObjectCsvWriterParams) =>

node_modules/.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/index.ts:20:14 - error TS2742: The inferred type of 'createObjectCsvWriter' cannot be named without a reference to '.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/lib/lang/object'. This is likely not portable. A type annotation is necessary.

20 export const createObjectCsvWriter = (params: ObjectCsvWriterParams) =>


node_modules/.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/lib/csv-writer-factory.ts:39:5 - error TS2742: The inferred type of 'createObjectCsvWriter' cannot be named without a reference to '.pnpm/csv-writer@1.6.0/node_modules/csv-writer/src/lib/lang/object'. This is likely not portable. A type annotation is necessary.

39     createObjectCsvWriter(params: ObjectCsvWriterParams) {`
kangshuisheng commented 1 year ago

Same mistake.

lukepearce commented 1 year ago

instead of using es6 import: import { createObjectCsvWriter } from "csv-writer"

use require: const createObjectCsvWriter = require("csv-writer").createObjectCsvWriter;

stevenle commented 1 year ago

FYI I'm getting this error using esbuild, since you're already using typescript and tsc, this feels like an easy fix. Just update your tsconfig to output a .d.ts declaration file to dist/index.d.ts and update "types" in package.json to point to the declaration file. Are you willing to accept a pull request for this? I'm happy to submit send one over.

piercy commented 1 year ago

Could this PR be merged? Seems like a simple change to massively improve the usability of the library.

brakmic commented 3 months ago

Hi @rajivkr,

I saw your issue about the build error when using the package with pnpm and NestJS. I've forked the original project and am working on fixing such issues. My fork only publishes JavaScript files and includes type declaration files, which should resolve the TypeScript errors you're encountering.

Check it out here:

Give it a try and let me know if it helps!

Best, Harris