1
votes

Using Typescript 3.* and momentjs for dates and I got compile time errors.

Error:(3, 13) TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'typeof moment' has no compatible call signatures.

so,I looked for a solution to solve this error. And find the following article, I did the same thing as the solution described in the article.

but I got compile time error, again.

Error:(1, 8) TS1192: Module '"/Users/hogehoge/Work/Work_Fork/hoge/node_modules/moment/moment"' has no default export.

Here is My tsconfig and my programs.

{
  "compilerOptions": {
    "moduleResolution": "node",
    "skipLibCheck": false,
    "target": "es5",
    "module": "commonjs",
    "lib": ["es2017", "dom"],
    "experimentalDecorators": true,
    "allowJs": false,
    "jsx": "react",
    "sourceMap": true,
    "strict": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
    "esModuleInterop": true,
    "removeComments": true,
    "newLine": "LF",
    "downlevelIteration": true,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": false
  },
  "exclude": ["node_modules"]
}

import moment from 'moment';

console.log(moment().format('YYYY-MM-DD'))
1

1 Answers

2
votes

I didn't have your package.json, so I reproduced your situation this way:

npm init
npm i typescript moment @types/node

File test.ts

let moment = require("moment");
console.log(moment().format('YYYY-MM-DD'))

(using require instead of import)

Then executed the "compiler":

_modules/.bin/tsc test.ts

No errors, this way it worked fine for me. As of today, the script returns 2019-09-30.