couchdb-nano
couchdb-nano copied to clipboard
Error under electron: Adapter 'http' is not available in the build
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
- scrap axios and use fetch :-)
- document a way to change axios adapter from outside. Agent option seems that does not change anything.
Steps to Reproduce (for bugs)
- Create an Electron application
- In the main.js (that is, the Node process) add the lines listed above (putting a known CouchDB url).
- Run
npm run dev
- 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
Seems already have a pull request here https://github.com/apache/couchdb-nano/pull/314
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: @.***>
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
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
I have the same error
@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
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