Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
crystalfp opened this issue Aug 23, 2023 · 7 comments
Open

Comments

@crystalfp
Copy link

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 axios/axios#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
Copy link
Author

Seems already have a pull request here #314

@glynnbird
Copy link
Contributor

glynnbird commented Aug 23, 2023 via email

@crystalfp
Copy link
Author

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
Copy link
Author

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

@MiniSuperDev
Copy link

I have the same error

@crystalfp
Copy link
Author

@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
Copy link
Author

crystalfp commented Oct 26, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants