Vonage / vonage-node-sdk

Vonage API client for Node.js. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Apache License 2.0
375 stars 178 forks source link

[Bug]: compability issue with node-fetch v3 #919

Closed weisheng-homage closed 3 months ago

weisheng-homage commented 4 months ago

Node Version

20.x

Platform

Mac (Apple Silcon)

SDK Version

3.12.2

Code Sample

non working sample: https://github.com/weisheng-homage/vonage_broke_ts

this issue go away when skipLibCheck is true we would like to keep that option disable for type safety reasons, since we also use many other internal library that we maintain ourself.

Expected Behavior

not have the error message

Actual Behavior

getting this instead

node_modules/@vonage/server-client/dist/client.d.ts:1:26 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("node-fetch")' call instead.

1 import { Response } from 'node-fetch';
                           ~~~~~~~~~~~~

node_modules/@vonage/vetch/dist/errors/vetchError.d.ts:2:26 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("node-fetch")' call instead.

2 import { Response } from 'node-fetch';
                           ~~~~~~~~~~~~

Found 2 errors in 2 files.

Errors  Files
     1  node_modules/@vonage/server-client/dist/client.d.ts:1
     1  node_modules/@vonage/vetch/dist/errors/vetchError.d.ts:2
manchuck commented 4 months ago

@weisheng-homage a new minor release was published earlier this week (3.13.0). Could you try that version?

weisheng-homage commented 4 months ago

hi @manchuck thanks for the response. I don't think 3.13.0 is published yet. the latest is 3.12.2 on npmjs.com and github releases.

this is what i get when i run the npm command to install

% npm i @vonage/server-sdk@3.13.0 --save
npm ERR! code ETARGET
npm ERR! notarget No matching version found for @vonage/server-sdk@3.13.0.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in: .npm/_logs/2024-02-14T01_05_20_963Z-debug-0.log

detailed npm log says the same thing

37 silly fetch manifest @vonage/server-sdk@3.13.0
38 timing arborist:ctor Completed in 0ms
39 http fetch GET 200 https://registry.npmjs.org/@vonage%2fserver-sdk 8ms (cache hit)
40 silly placeDep ROOT @vonage/server-sdk@ OK for: vonage_broke_ts@1.0.0 want: 3.13.0
41 timing idealTree:#root Completed in 12ms
42 timing idealTree:node_modules/@vonage/server-sdk Completed in 0ms
43 timing idealTree:buildDeps Completed in 12ms
44 timing idealTree:fixDepFlags Completed in 0ms
45 timing idealTree Completed in 23ms
46 timing command:i Completed in 29ms
47 verbose type version
48 verbose stack @vonage/server-sdk: No matching version found for @vonage/server-sdk@3.13.0.
48 verbose stack     at module.exports (/usr/local/lib/node_modules/npm/node_modules/npm-pick-manifest/lib/index.js:209:23)
48 verbose stack     at RegistryFetcher.manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/registry.js:119:22)
48 verbose stack     at async #nodeFromEdge (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1049:19)
48 verbose stack     at async #buildDepStep (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:917:11)
48 verbose stack     at async Arborist.buildIdealTree (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:196:7)
48 verbose stack     at async Promise.all (index 1)
48 verbose stack     at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:159:5)
48 verbose stack     at async Install.exec (/usr/local/lib/node_modules/npm/lib/commands/install.js:152:5)
48 verbose stack     at async module.exports (/usr/local/lib/node_modules/npm/lib/cli-entry.js:61:5)
49 verbose cwd vonage_broke_ts
50 verbose Darwin 23.1.0
51 verbose node v20.11.0
52 verbose npm  v10.2.4
53 error code ETARGET
54 error notarget No matching version found for @vonage/server-sdk@3.13.0.
55 error notarget In most cases you or one of your dependencies are requesting
55 error notarget a package version that doesn't exist.
56 verbose exit 1
57 timing npm Completed in 145ms
58 verbose unfinished npm timer reify 1707872721079
59 verbose unfinished npm timer reify:loadTrees 1707872721083
60 verbose code 1
weisheng-homage commented 4 months ago

in case anyone stumble into the same issue. there are at least 2 workarounds

additional note: fetch is consider experimental before node 21 - it works well for our use cases, your experience might varies.

manchuck commented 4 months ago

@weisheng-homage Apologies again, I'm at ConFoo and must have missed publishing 3.13. During the Con I published 3.13.1 to address an issue with the public key reading. I have confirmed that 3.13.1 is published: https://www.npmjs.com/package/@vonage/server-sdk/v/3.13.1