apache / couchdb-nano

Nano: The official Apache CouchDB library for Node.js
https://www.npmjs.com/package/nano
Apache License 2.0
651 stars 165 forks source link

TypeError: Nano is not a function #328

Closed utkapodsousom closed 1 year ago

utkapodsousom commented 1 year ago

I'm trying to get nano to work in my project. According to docs, if you want to import as module, you do:

import * as Nano from 'nano';
let n = Nano('http://USERNAME:PASSWORD@localhost:5984');

Current Behavior

I get an error on the second line TypeError: Nano is not a function

We all know it IS a function, however I cannot solve the issue.

glynnbird commented 1 year ago

You could try:

import Nano from 'nano';
const nano = Nano(process.env.COUCH_URL);
let db = nano.db.use('cities');
db.list({limit:5}).then(console.log)

I got this to work with the Typscript command:

tsc --esModuleInterop true test.ts
louwers commented 1 year ago

I tried your suggestion but it is giving me Cannot read properties of undefined (reading 'use')

import Nano from 'nano'

...

  const nano = Nano(couchDbUrl)
  console.log(Nano) // [Function: dbScope]
  const nano = Nano(couchDbUrl)
  console.log(nano)

The last log statement returns something conforming docScope which does not have a use method contrary to what the docs state.