couchdb-nano icon indicating copy to clipboard operation
couchdb-nano copied to clipboard

Error under electron: Adapter 'http' is not available in the build

Open crystalfp opened this issue 10 months ago • 7 comments

Expected Behavior

Used nano without errors under Node 20.4.0. I want to use the exactly same code under Electron that bundles Node 18.16.1

Current Behavior

At the first call to nano

import Nano from "nano";
const nano = Nano({url: "my-CouchDB-url", requestDefaults: {timeout: 120_000}});
const databaseList = await nano.db.list();

I receive the error:

Adapter 'http' is not available in the build

Seems the error is generated by axios and seems the solution is to move to fetch. There is a possible workaround at https://github.com/axios/axios/issues/5523 but setting agent in the requestDefaults has no effect.

Possible Solution

  1. scrap axios and use fetch :-)
  2. document a way to change axios adapter from outside. Agent option seems that does not change anything.

Steps to Reproduce (for bugs)

  1. Create an Electron application
  2. In the main.js (that is, the Node process) add the lines listed above (putting a known CouchDB url).
  3. Run npm run dev
  4. See the error

Context

Well, this problem blocks entirely my porting of the client-server application under Electron. If there is no solution I have to scrap CouchDB and move to another DB.

Your Environment

  • Version used: 10.1.2
  • Browser Name and version: Electron 26.0.0 that runs Node 18.16.1. Not run in browser.
  • Operating System and version (desktop or mobile): Windows 11 64bits desktop
  • Link to your project: Not public

crystalfp avatar Aug 23 '23 06:08 crystalfp

Seems already have a pull request here https://github.com/apache/couchdb-nano/pull/314

crystalfp avatar Aug 23 '23 06:08 crystalfp

Yes there's a branch that replaces axios with fetch, but haven't got round to merging it yet. It would be great if you could test it i.e replace your nano dependency with something like github.com/apache/couchdb-nano#fetch

On Wed, 23 Aug 2023 at 07:56, Mario Valle @.***> wrote:

Seems already have a pull request here #314 https://github.com/apache/couchdb-nano/pull/314

— Reply to this email directly, view it on GitHub https://github.com/apache/couchdb-nano/issues/332#issuecomment-1689386258, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFKMROWFWNAXLDWDSOP663XWWSTLANCNFSM6AAAAAA32636AQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

glynnbird avatar Aug 23 '23 08:08 glynnbird

With pleasure, @glynnbird ! Simply overwrote the package directory with the fetch branch content (Bad bad!). Besides installing undici and removing requestDefaults at least the opening of the database succeeded. Now I could continue with porting and testing. Have a great day! mario

crystalfp avatar Aug 23 '23 08:08 crystalfp

Dear @glynnbird , the modified version works perfectly (at least in my application)! I hope soon will be release as the official nano version. Currently every time I install a package, the nano package reverts to the official version and I have to overwrite it again with your "fetch" branch. Thanks again! mario

crystalfp avatar Aug 28 '23 07:08 crystalfp

I have the same error

MiniSuperDev avatar Sep 21 '23 05:09 MiniSuperDev

@MiniSuperDev The workaround until the nano package will be updated is to do:

npm i "https://github.com/apache/couchdb-nano#fetch"

Now magically the application works. Hope it heps mario

crystalfp avatar Sep 21 '23 06:09 crystalfp

Any news about merging the change in the main distribution? Thanks!

Waiting on the official release also because the suggested way to set options elicit an error in Typescript:

import undici from "undici";
const undiciOptions = new undici.Agent({bodyTimeout: 120_000});
const db = Nano({url: databaseURL, agentOptions: undiciOptions});

The strange error on agentOptions is:

Type 'Agent' is not assignable to type 'typeof Agent | typeof Dispatcher | AgentOptions | typeof MockAgent | undefined'.
  Type 'Agent' is missing the following properties from type 'typeof MockAgent': prototype, getEventListeners, addAbortListener, errorMonitor, and 5 more.ts(2322)

Thanks for looking! mario

crystalfp avatar Oct 26 '23 04:10 crystalfp