Maarrk
Maarrk•6mo ago

Error with fetch called from npm module

I am trying to use the tsdav NPM package with Deno, and have run into a problem with making an HTTP request, which seems specific to Deno. When I try to call any request method from the library, I get an error with HttpsClientRequest somewhere deep within some compatibility layer:
error: TypeError: Cannot read properties of undefined (reading 'write')
at HttpsClientRequest._writeRaw (ext:deno_node/_http_outgoing.ts:422:24)
at HttpsClientRequest._send (ext:deno_node/_http_outgoing.ts:408:17)
at HttpsClientRequest.write_ (ext:deno_node/_http_outgoing.ts:316:16)
at HttpsClientRequest.write (ext:deno_node/_http_outgoing.ts:293:17)
at writeToStream (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/node-fetch/2.7.0/lib/index.js:654:8)
at file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/node-fetch/2.7.0/lib/index.js:1726:3
at new Promise (<anonymous>)
at Function.fetch (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/node-fetch/2.7.0/lib/index.js:1447:9)
at Function.fetch (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/cross-fetch/4.0.0/dist/node-ponyfill.js:10:20)
at file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/tsdav/2.0.7/dist/tsdav.cjs.js:198:42
error: TypeError: Cannot read properties of undefined (reading 'write')
at HttpsClientRequest._writeRaw (ext:deno_node/_http_outgoing.ts:422:24)
at HttpsClientRequest._send (ext:deno_node/_http_outgoing.ts:408:17)
at HttpsClientRequest.write_ (ext:deno_node/_http_outgoing.ts:316:16)
at HttpsClientRequest.write (ext:deno_node/_http_outgoing.ts:293:17)
at writeToStream (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/node-fetch/2.7.0/lib/index.js:654:8)
at file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/node-fetch/2.7.0/lib/index.js:1726:3
at new Promise (<anonymous>)
at Function.fetch (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/node-fetch/2.7.0/lib/index.js:1447:9)
at Function.fetch (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/cross-fetch/4.0.0/dist/node-ponyfill.js:10:20)
at file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/tsdav/2.0.7/dist/tsdav.cjs.js:198:42
Possibly relevant links: - The tsdav library: https://tsdav.vercel.app/ https://www.npmjs.com/package/tsdav - Implementation of fetch that gets called by them: https://www.npmjs.com/package/node-fetch - The test showing this error: https://github.com/Maarrk/silverbullet-carddav/blob/ed209cb939b935cfe50169dbff7ba8ed2df7771c/online.test.ts#L27-L30 I've only used Deno for a few weeks but I really like it so far, thanks in advance for any help or pointers to relevant docs 😊 I couldn't even find the _http_outgoing.ts in my local deno folder on my own...
tsdav | tsdav
webdav request made easy
npm
tsdav
WebDAV, CALDAV, and CARDDAV client for Nodejs and the Browser. Latest version: 2.0.7, last published: 2 months ago. Start using tsdav in your project by running npm i tsdav. There are 4 other projects in the npm registry using tsdav.
npm
node-fetch
A light-weight module that brings Fetch API to node.js. Latest version: 3.3.2, last published: 7 months ago. Start using node-fetch in your project by running npm i node-fetch. There are 33917 other projects in the npm registry using node-fetch.
GitHub
silverbullet-carddav/online.test.ts at ed209cb939b935cfe50169dbff7b...
A SilverBullet Plug to sync personal contacts with a CardDAV server - Maarrk/silverbullet-carddav
3 Replies
Deno AI Helper
Deno AI Helper•6mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the error message you've provided, it seems like there might be an issue with the compatibility layer that allows npm packages to work with Deno. The error message indicates that there's a problem with the HttpsClientRequest object, specifically with the write method being called on an undefined object. This could be due to a variety of reasons, such as the npm package you're using not being fully compatible with Deno's Node compatibility layer, or it could be a bug within the compatibility layer itself. Since the error is occurring within the internals of the compatibility layer (ext:deno_node/_http_outgoing.ts), it's not something that can be easily fixed without looking into the compatibility layer's implementation. This advice is not based on the Deno documentation, so please double-check the accuracy of this advice. As a general suggestion, you might want to ensure that you're using the latest version of Deno and that any npm packages you're using are known to be compatible with Deno. If the issue persists, you might consider reporting it to the Deno repository or the repository of the npm package if you suspect the issue is on their end. Remember that not all npm packages are guaranteed to work seamlessly with Deno, especially if they rely on Node.js-specific APIs that may not have equivalents in Deno or may not be fully supported by Deno's compatibility layer.
Maarrk
Maarrk•6mo ago
In the meantime I have tried the code with Node v16.15.0, and it works as expected, so doesn't seem like a problem with my code
Maarrk
Maarrk•6mo ago
I ran into exactly the same error with another library:
dav auth test => ./online.test.ts:16:6
error: TypeError: Cannot read properties of undefined (reading 'write')
at HttpsClientRequest._writeRaw (ext:deno_node/_http_outgoing.ts:422:24)
at HttpsClientRequest._send (ext:deno_node/_http_outgoing.ts:408:17)
at HttpsClientRequest.write_ (ext:deno_node/_http_outgoing.ts:316:16)
at HttpsClientRequest.write (ext:deno_node/_http_outgoing.ts:293:17)
at exports.XMLHttpRequest.send (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/xmlhttprequest/1.8.0/lib/XMLHttpRequest.js:467:17)
at XMLHttpRequest.send (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:3416:15)
at Basic.callee$2$0$ (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:2960:26)
at tryCatch (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:121:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:294:22)
at GeneratorFunctionPrototype.Gp.<computed> [as next] (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:330:19)
dav auth test => ./online.test.ts:16:6
error: TypeError: Cannot read properties of undefined (reading 'write')
at HttpsClientRequest._writeRaw (ext:deno_node/_http_outgoing.ts:422:24)
at HttpsClientRequest._send (ext:deno_node/_http_outgoing.ts:408:17)
at HttpsClientRequest.write_ (ext:deno_node/_http_outgoing.ts:316:16)
at HttpsClientRequest.write (ext:deno_node/_http_outgoing.ts:293:17)
at exports.XMLHttpRequest.send (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/xmlhttprequest/1.8.0/lib/XMLHttpRequest.js:467:17)
at XMLHttpRequest.send (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:3416:15)
at Basic.callee$2$0$ (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:2960:26)
at tryCatch (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:121:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:294:22)
at GeneratorFunctionPrototype.Gp.<computed> [as next] (file:///C:/Users/Marek/AppData/Local/deno/npm/registry.npmjs.org/dav/1.8.0/dav.js:330:19)
https://www.npmjs.com/package/dav
npm
dav
WebDAV, CalDAV, and CardDAV client for nodejs and the browser. Latest version: 1.8.0, last published: 6 years ago. Start using dav in your project by running npm i dav. There are 10 other projects in the npm registry using dav.