node-csvtojson
node-csvtojson copied to clipboard
Error importing
I have done this:
npm i csvtojson -D
npm i @types/csvtojson -D
In my typescript file:
import * as csvtojson from 'csvtojson;
csvtojson().fromFile(csvFilePath)
In my console: Error Message:
Error: TSError: ⨯ Unable to compile TypeScript: someTypeScriptFile.ts:35:11 - error TS2349: This expression is not callable. Type '{ default: (param?: Partial, options?: TransformOptions) => Converter; }' has no call signatures.
Here is my tsconfig.json:
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./dist/out-tsc",
"noImplicitAny": false,
"noImplicitReturns": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"allowJs": true,
"paths": {},
"types": ["jasmine", "node", "jasminewd2"]
},
"include": [],
"exclude": ["./node_modules"],
"compileOnSave": false
}
Not sure if this is your problem, but you're missing a '
before the semicolon:
import * as csvtojson from 'csvtojson;
Should be:
import * as csvtojson from 'csvtojson';
...which still doesn't work 😆
But this does:
import csvtojson from 'csvtojson';
Yes this works, but only if you set esModuleInterop": true
in yout tsconfig. Haven't found another way.