Deno not recognizing default export from npm package 'unstorage' as a function
Hello everyone,
I am attempting to set up
unstorage
with the Deno KV driver, as per https://unstorage.unjs.io/drivers/deno
When I import the driver and attempt to call it, the LSP reports that denoKVdriver
lacks a call signature, and type-checking also fails:
If I invoke denoKVdriver.default()
, the LSP no longer reports the error, but type-checking still fails.
Relevant d.ts
:
Code:
deno.json
for workspace member:
deno.json
for workspace:
Is there a way to work around this?5 Replies
It looks like their driver directory doesn't have a general entry file for types and their package.json exports is set up in a way that it may not be able to automatically find it. Try adding a triple slash reference to the top of the file
/// <reference types="unstorage/drivers/deno-kv.d.ts"/>
Thanks for your reply! When adding the triple slash directive to the file, the lsp reports that the export can't be resolved:
y'know ironically, I don't think their package is really configured to be consumed in Deno. It's structured for Node.js
It's not great but you could potentially resolve it as such:
That.. feels bad, but it does work. Thanks again for your help!
D'oh! Missed this section in the docs. For anyone reading this: https://docs.deno.com/runtime/fundamentals/node/#importing-types
Deno
Node and npm Compatibility
Guide to using Node.js modules and npm packages in Deno. Learn about compatibility features, importing npm packages, and differences between Node.js and Deno environments.