node-csvtojson icon indicating copy to clipboard operation
node-csvtojson copied to clipboard

Error importing

Open kshrestha99 opened this issue 3 years ago • 3 comments

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
}

kshrestha99 avatar Mar 01 '21 02:03 kshrestha99

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';

abettermap avatar Aug 13 '21 17:08 abettermap

...which still doesn't work 😆

But this does:

import csvtojson from 'csvtojson';

abettermap avatar Aug 13 '21 17:08 abettermap

Yes this works, but only if you set esModuleInterop": true in yout tsconfig. Haven't found another way.

udondan avatar Sep 08 '22 12:09 udondan