Typescript SyntaxError: Unexpected token '.' during compilation
phollaki opened this issue · 1 comments
phollaki commented
Current Behavior
When attempting to use the Vonage SDK with TypeScript, a syntax error is encountered during compilation. The error specifically points to the unexpected token '.' in the client.js file of the Vonage library.
// Create Vonage client
this.client = new Vonage(new Auth({
apiKey: sms.smsKeyVonage,
apiSecret: sms.smsSecretVonage,
}));
// Also tried with
this.client = new Vonage(new Auth({
apiKey: sms.smsKeyVonage,
apiSecret: sms.smsSecretVonage,
}), undefined);
// later in the code when I try to send an sms
this.vonageClient.sms.send({ to: phone, from: sms.smsFrom, text: message });
During compilation, the following error is thrown:
/node_modules/@vonage/server-client/dist/client.js:46
restHost: options?.restHost || 'https://rest.nexmo.com',
^
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (***/node_modules/@vonage/server-client/dist/index.js:18:16)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (***/node_modules/@vonage/accounts/dist/accounts.js:4:25)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (***/node_modules/@vonage/accounts/dist/index.js:4:18)
line 41-53 in client.js -> /node_modules/@vonage/server-client/dist/client.js:46
constructor(credentials, options) {
this.auth = !Object.prototype.hasOwnProperty.call(credentials, 'getQueryParams')
? new auth_1.Auth(credentials)
: credentials;
this.config = {
restHost: options?.restHost || 'https://rest.nexmo.com',
apiHost: options?.apiHost || 'https://api.nexmo.com',
videoHost: options?.videoHost || 'https://video.api.vonage.com',
proactiveHost: options?.proactiveHost || 'https://api-eu.vonage.com',
responseType: options?.responseType || vetch_1.ResponseTypes.json,
timeout: null,
};
}
Context
My tsconfigs in a mono-repo:
core
{
"compilerOptions": {
"allowJs": false,
"jsx": "react",
"strict": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"noImplicitThis": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowSyntheticDefaultImports": true,
"module": "commonjs",
"resolveJsonModule": true,
"experimentalDecorators": true,
"sourceMap": true,
"removeComments": true
},
"exclude": [
"node_modules",
"lib",
"dist",
"projects/playground",
"**/lib/**",
"**/dist/**",
"cypress/**/*",
"./cypress.config.ts"
]
}
backend
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2018",
"lib": ["es2018"],
"types": ["reflect-metadata", "node", "jest", "koa-bodyparser", "puppeteer"],
"experimentalDecorators": true,
"allowJs": true,
"outDir": "dist",
"rootDir": "src",
"sourceMap": true,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.json"],
}
Your Environment
- Typescript: ^3.9.0,
- SDK Versions: ^3.5.1 | 3.0.0 | 3.0.12 | 3.0.18,
- Vonage/Auth Version: ^1.3.0,
- Node Version: v12.22.12:
- Operating System and version: MacOS
Thanks in advance!
phollaki commented
I had to switch to Node 14, or downgrade to sdk version 2.11.3. Then everything works smoothly.