csv-writer icon indicating copy to clipboard operation
csv-writer copied to clipboard

Build error when using with pnpm and nestjs

Open rajivkr opened this issue 2 years ago • 5 comments

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

`node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/index.ts:11:14 - error TS2742: The inferred type of 'createArrayCsvStringifier' cannot be named without a reference to '.pnpm/[email protected]/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/[email protected]/node_modules/csv-writer/src/index.ts:14:14 - error TS2742: The inferred type of 'createObjectCsvStringifier' cannot be named without a reference to '.pnpm/[email protected]/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/[email protected]/node_modules/csv-writer/src/index.ts:17:14 - error TS2742: The inferred type of 'createArrayCsvWriter' cannot be named without a reference to '.pnpm/[email protected]/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/[email protected]/node_modules/csv-writer/src/index.ts:20:14 - error TS2742: The inferred type of 'createObjectCsvWriter' cannot be named without a reference to '.pnpm/[email protected]/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/[email protected]/node_modules/csv-writer/src/index.ts:20:14 - error TS2742: The inferred type of 'createObjectCsvWriter' cannot be named without a reference to '.pnpm/[email protected]/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/[email protected]/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/[email protected]/node_modules/csv-writer/src/lib/lang/object'. This is likely not portable. A type annotation is necessary.

39 createObjectCsvWriter(params: ObjectCsvWriterParams) {`

rajivkr avatar Nov 03 '22 08:11 rajivkr

Same mistake.

kangshuisheng avatar Mar 03 '23 05:03 kangshuisheng

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

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

lukepearce avatar Apr 06 '23 12:04 lukepearce

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.

stevenle avatar Apr 24 '23 23:04 stevenle

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

piercy avatar Sep 20 '23 08:09 piercy

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

brakmic avatar Jul 16 '24 09:07 brakmic