question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

typings index.d.ts failing transpilation, needs an ts-ignore bypass.

See original GitHub issue

Using @vonage/server-sdk with typescript doesn’t transpile without an unrecommended bypass, but then it doesn’t work at all.

Expected Behavior

The expected behavior is to use the package without ts notations

Current Behavior

The current behavior is the next.

import * as Vonage from '@vonage/server-sdk';
const nexmo = new Vonage({
      apiKey: 'asdf',
      apiSecret: 'asdf',
    });
// throws:
// TS2351: This expression is not constructable.
// Type 'typeof import("@vonage/server-sdk")' has no construct signatures
import Vonage from '@vonage/server-sdk';
const nexmo = new Vonage({
      apiKey: 'asdf',
      apiSecret: 'asdf',
    });
// ide don't complain, but when executing the bundle it throws a fatal error:
// TypeError: server_sdk_1.default is not a constructor

Context

Now it needs to be used with this ts notations:

import * as Vonage from '@vonage/server-sdk';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const nexmo = new Vonage({
      apiKey: 'asdf',
      apiSecret: 'asdf',
    });
const from = 'Vonage APIs';
const to = '...';
const text = 'Hello from Vonage SMS API';

nexmo.message.sendSms(from, to, text, {}, (err, data) => {
   console.log(err);
   console.log(data);
});
// sms received

Your Environment

  • SDK Version: “2.10.4”
  • Node Version: v14.15.1
  • TSC Version: 4.0.3
  • Operating System and version: Ubuntu 20.04.1 LTS

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kellyjandrewscommented, Feb 25, 2021

@visioncored - you may also need to add the following config:

        "esModuleInterop": true,
        "moduleResolution": "node",

I just about have things fixed up.

1reaction
visioncoredcommented, Feb 22, 2021

@kellyjandrews I also encountered this issue when I was trying out the SMS API in Firebase Cloud Functions. Here is the .tsconfig from my end.

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to force tsc to ignore node_modules folder?
To do so, the compiler needs the definition of a module, this could be a .ts file for your own code, or a...
Read more >
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
Read more >
JSDoc typings: all the benefits of TypeScript, with none of the ...
How you can use JSDoc typings to get all the benefits of TypeScript, without any transpilation.
Read more >
TypeScript - Cypress Documentation
Cypress ships with official type declarations for TypeScript. This allows you to write your tests in TypeScript. Install TypeScript To use TypeScript.
Read more >
A Complete Guide to Using TypeScript in Node.js - Better Stack
TypeScript is a superset of JavaScript that brings static typing capabilities to the ... Learn more about when to use ts-ignore or ts-expect-error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found