cloudant / nodejs-cloudant

Cloudant Node.js client library
Apache License 2.0
255 stars 90 forks source link

problems using promises plugin `cloudant.db.destroy(...).then is not a function #346

Closed csantanapr closed 6 years ago

csantanapr commented 6 years ago

Bug Description

Migrating code from require('cloudant') to require('@cloudant/cloudant') and using promise I get error then is not a function.

This is part of enabling IBM Functions users to use new nodejs:10 runtime that npm package cloudant is removed and the `@cloudant/cloudant' is included instead and all user encourage to migrate their code to the new library.

sorry if this is a stupid mistake using the new lib.

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

Here is code sample to reproduce

const Cloudant = require("@cloudant/cloudant")
const cloudant = Cloudant({ account: process.env.USERNAME, password: process.env.PASSWORD, plugin: 'promises' })
const dbName = 'carlos_db'
cloudant.db.destroy(dbName)
    .then(function () {
        console.log('The database was clean')
    })
    .catch(function (e) {
        console.error(e)
    })

2. What you expected to happen

No errors and a print message about success or catched error Using ` coderequire("cloudant")` works:

node reproduce_cloudant.js
{ error: 'not_found',
  reason: 'Database does not exist.',
  statusCode: 404 }

3. What actually happened

I get error cloudant.db.destroy(...).then is not a function

node reproduce_cloudant.js
reproduce_cloudant.js:5
    .then(function () {
     ^

TypeError: cloudant.db.destroy(...).then is not a function
    at Object.<anonymous> (/Users/csantanapr/Documents/dev/whisk/git/ibm-functions/runtime-nodejs/reproduce_cloudant.js:5:6)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

Environment details

csantanapr commented 6 years ago

Having same issue with db.insert() ".then is not a function"

smithsz commented 6 years ago

Plugins must be passed via the plugins parameter in the Cloudant client constructor (formerly known as plugin).

Example:

const cloudant = Cloudant({ account: process.env.USERNAME, password: process.env.PASSWORD, plugins: 'promises' })

The plugins parameter can also take an array to support multiple plugins, see here.

Take a look at the API migration document for further info.

csantanapr commented 6 years ago

Oh, didn’t realize that was a change, can we catch this early? Throw an exception if the user uses the formerly “plugin”?