typescript error with `verbatimModuleSyntax: true` in tsconfig.json
If we have the following in our tsconfig.json:
{
"compilerOptions": {
"skipLibCheck": true,
// https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax
"verbatimModuleSyntax": true
},
"exclude": ["node_modules"]
}
The following error occurs when running tsc:
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/index.ts:2:5 - error TS1484: 'ArrayCsvStringifierParams' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
2 ArrayCsvStringifierParams,
~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/index.ts:4:5 - error TS1484: 'ObjectCsvStringifierParams' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
4 ObjectCsvStringifierParams
~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/index.ts:6:9 - error TS1484: 'ArrayCsvWriterParams' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
6 import {ArrayCsvWriterParams, CsvWriterFactory, ObjectCsvWriterParams} from './lib/csv-writer-factory';
~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/index.ts:6:49 - error TS1484: 'ObjectCsvWriterParams' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
6 import {ArrayCsvWriterParams, CsvWriterFactory, ObjectCsvWriterParams} from './lib/csv-writer-factory';
~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifier-factory.ts:4:9 - error TS1484: 'ObjectStringifierHeader' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
4 import {ObjectStringifierHeader} from './record';
~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifiers/abstract.ts:2:9 - error TS1484: 'Field' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
2 import {Field} from '../record';
~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifiers/array.ts:3:9 - error TS1484: 'Field' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
3 import {Field} from '../record';
~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifiers/object.ts:3:9 - error TS1484: 'Field' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
3 import {Field, ObjectHeaderItem, ObjectStringifierHeader} from '../record';
~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifiers/object.ts:3:16 - error TS1484: 'ObjectHeaderItem' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
3 import {Field, ObjectHeaderItem, ObjectStringifierHeader} from '../record';
~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifiers/object.ts:3:34 - error TS1484: 'ObjectStringifierHeader' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
3 import {Field, ObjectHeaderItem, ObjectStringifierHeader} from '../record';
~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifiers/object.ts:4:19 - error TS1484: 'ObjectMap' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
4 import {isObject, ObjectMap} from '../lang/object';
~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-writer-factory.ts:3:9 - error TS1484: 'ObjectStringifierHeader' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
3 import {ObjectStringifierHeader} from './record';
~~~~~~~~~~~~~~~~~~~~~~~
node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/field-stringifier.ts:1:9 - error TS1484: 'Field' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
1 import {Field} from './record';
~~~~~
Found 13 errors in 7 files.
Errors Files
4 node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/index.ts:2
1 node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifier-factory.ts:4
1 node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifiers/abstract.ts:2
1 node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifiers/array.ts:3
4 node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-stringifiers/object.ts:3
1 node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/csv-writer-factory.ts:3
1 node_modules/.pnpm/[email protected]/node_modules/csv-writer/src/lib/field-stringifier.ts:1
ELIFECYCLE Command failed with exit code 2.
I just had this same issue. The problem is that the NPM package includes the Typescript source files, not just the compiled Javascript and the *.d.ts files.
This means it's hitting this bug from 2020 and failing the build.
As a temporary workaround you can delete the node_modules/csv-writer/src/ folder, but the proper solution is that the src folder shouldn't be included as part of the NPM package.
Yeah, thanks @adam-nielsen. This should indeed be removed: https://github.com/ryu1kn/csv-writer/blob/4b36c0c42ae2c8b7ca3ee9567aabf61e9dab9bd2/package.json#L35
Doesn't look like csv-writer is being actively maintained anymore though, so I've switched to using csv-stringify.