Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Error : Agent is not a constructor while using 54.0.0 #3938

Closed
akp111 opened this issue Nov 16, 2021 · 13 comments · Fixed by #3949
Closed

Error : Agent is not a constructor while using 54.0.0 #3938

akp111 opened this issue Nov 16, 2021 · 13 comments · Fixed by #3949
Assignees
Labels
kind/bug A bug in existing code (including security flaws) P0 Critical: Tackled by core team ASAP

Comments

@akp111
Copy link

akp111 commented Nov 16, 2021

Version: 53.0.1 and 54.0.0

Platform: Linux

Severity: High Severity

Issue:
A few days back IPFS on the server end started throwing the following error
Agent is not a constructor
I was getting this error while initializing the ipfs instance.

 try {
      ipfs = await create('/ip4/0.0.0.0/tcp/5001');
    }
    catch (err) {
      Logger.error(err)
}

@akp111 akp111 added the need/triage Needs initial labeling and prioritization label Nov 16, 2021
@welcome
Copy link

welcome bot commented Nov 16, 2021

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review.
In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment.
Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

@jdeepee
Copy link

jdeepee commented Nov 19, 2021

I am also getting the error on the latest version 0.60.0

@vinkabuki
Copy link

vinkabuki commented Nov 19, 2021

Same for me on 53.0.1 and 54.0.0

@StrawberryChocolateFudge

same for me on the latest ^54.0.1 and 53.0.1
downgraded to 52.0.5 and that works so the problem was introduced after.

@achingbrain
Copy link
Member

What version of node are you running?

@StrawberryChocolateFudge

@achingbrain
I'm on v16.13.0 Active LTS

@EmiM
Copy link

EmiM commented Nov 22, 2021

Node v14.15.5
ipfs@0.59.1

For me this error occurs probably because default Agent is now taken from agent.browser.js instead of agent.js (ipfs-http-client) resulting in Agent being undefined.

@momack2 momack2 added the P0 Critical: Tackled by core team ASAP label Nov 23, 2021
@achingbrain
Copy link
Member

I'm having trouble replicating this, can you tell me a bit more about your setup please, supply a stack trace and preferably provide a repro case that shows the error?

You say "IPFS on the server end" but await create('/ip4/0.0.0.0/tcp/5001') looks more like you're trying to create an instance of the http client?

default Agent is now taken from agent.browser.js instead of agent.js

The file the Agent class is loaded from is controlled by the exports map in ipfs-core-utils/package.json with "browser" returning nothing and "import"/"require" returning http.Agent or https.Agent depending on the URL being used.

It's also loaded by the /agent file in the published tarball, but that file is only there for compatibility with tools that use resolve like jest and browserify and should be ignored by any node.js that supports the exports map.

Agent itself is only instantiated if the environment is node.js

If you're getting the "browser" export in node.js there must be something about your project/env that's triggering this as it's not intended or documented behaviour.

@EmiM
Copy link

EmiM commented Nov 23, 2021

Thank you for the response.

That's what I suspected (the problem being our project) however it was working for us before.
The error appeared when I upgraded ipfs from 0.52.3 to 0.59.1 (along with upgrading orbitdb to 0.28.0 and all its dependencies).
I use jest for testing and have testEnvironment set to 'node'.

I printed the env_js and default agent in ipfs-http-client core.js to see what's going on:

console.log
    ipfs-core -> ipfs-http-client -> lib.core.js. Env: {
      isTest: true,
      isElectron: false,
      isElectronMain: false,
      isElectronRenderer: false,
      isNode: true,
      isBrowser: false,
      isWebWorker: false,
      isEnvWithDom: false,
      isReactNative: false
    }

      at normalizeOptions (node_modules/ipfs-core/node_modules/ipfs-http-client/cjs/src/lib/core.js:53:11)

  console.log
    ipfs-core -> ipfs-http-client -> lib.core.js. getAgent__default: { default: [Function: agent_browser] }

It looks like it knows that it's a node env but still reaches for agent.browser.js?

@achingbrain
Copy link
Member

Can you please share a link to your project or a repro repo with instructions on how to replicate this issue?

@EmiM
Copy link

EmiM commented Nov 23, 2021

Sure! TryQuiet/waggle#152
npm i
npm run test -- -t "IO proxy" (it's one of the few that fail)

@achingbrain achingbrain added kind/bug A bug in existing code (including security flaws) and removed need/triage Needs initial labeling and prioritization labels Nov 23, 2021
achingbrain added a commit to multiformats/js-multiformats that referenced this issue Nov 24, 2021
To fix bugs like ipfs/js-ipfs#3938 where
Jest ends up resolving browser specific code, use a version of
ipjs with the fix.
achingbrain added a commit to ipfs/aegir that referenced this issue Nov 24, 2021
To fix bugs like ipfs/js-ipfs#3938 where
Jest ends up resolving browser specific code, use a version of
ipjs with the fix.
achingbrain added a commit to ipfs/aegir that referenced this issue Nov 24, 2021
To fix bugs like ipfs/js-ipfs#3938 where Jest ends up resolving browser specific code, use a version of ipjs with the fix.
rvagg pushed a commit to multiformats/js-multiformats that referenced this issue Nov 24, 2021
To fix bugs like ipfs/js-ipfs#3938 where
Jest ends up resolving browser specific code, use a version of
ipjs with the fix.
achingbrain added a commit that referenced this issue Nov 24, 2021
Pulls in new ipjs which stubs files that require the node version of
modules.

Fixes #3938
achingbrain added a commit that referenced this issue Nov 24, 2021
Pulls in new ipjs which stubs files that require the node version of
modules.

Fixes #3938
@achingbrain
Copy link
Member

This should be fixed in ipfs@0.60.2 and ipfs-core@0.12.2. Please reopen if you're still seeing this problem.

EmiM added a commit to TryQuiet/waggle that referenced this issue Nov 24, 2021
The newest patch fixes "Agent is not a constructor" error introduced in one of the previous versions
ipfs/js-ipfs#3938
@EmiM
Copy link

EmiM commented Nov 24, 2021

Thank you! The new patch works for me :D

@lidel lidel added this to In Progress in Maintenance Priorities - JS Nov 26, 2021
@lidel lidel moved this from In Progress to Done in Maintenance Priorities - JS Nov 26, 2021
siepra added a commit to TryQuiet/waggle that referenced this issue Dec 13, 2021
* Upgrade orbitdb to 0.28.0 and its dependencies (libp2p@0.33.0, ipfs@0.59.0)

* Upgrade multiaddr
Add orbit-db-io to project dependencies, lack of it causes "IPFSAccessController.save ERROR: Error: Deprecated, use .toString()" and "Something went wrong Error: `undefined` is not supported by the IPLD Data Model and cannot be encoded"

* Upgrade libp2p-websockets

* Lint

* Add ipfs-log to dependencies

* Remove wrtc; fix Multiaddress import in test

* Fix

* Add jest setup with global.crypto

* Bump ipfs to 0.60.2
The newest patch fixes "Agent is not a constructor" error introduced in one of the previous versions
ipfs/js-ipfs#3938

* IPFS initialization fix - pass pregenerated peerID's private key as 'init' options to create method

* CI replication test - increase number of entries

* Cleanup

* Upgate changelog

* Fix/replace find free port (#161)

* Changed library for getting ports

* Fix test utils import

* send message instead ids

* Close websocket connection (#167)

Co-authored-by: Emilia Marczyk <emilia.marczyk@rumblefish.pl>
Co-authored-by: Wiktor Sieprawski <wiktor.sieprawski@rumblefish.pl>
Co-authored-by: bartosz.chyra <bartosz.chyra@rumblefish.pl>
siepra added a commit to TryQuiet/quiet that referenced this issue Dec 14, 2021
* Upgrade orbitdb to 0.28.0 and its dependencies (libp2p@0.33.0, ipfs@0.59.0)

* Upgrade multiaddr
Add orbit-db-io to project dependencies, lack of it causes "IPFSAccessController.save ERROR: Error: Deprecated, use .toString()" and "Something went wrong Error: `undefined` is not supported by the IPLD Data Model and cannot be encoded"

* Upgrade libp2p-websockets

* Lint

* Add ipfs-log to dependencies

* Remove wrtc; fix Multiaddress import in test

* Fix

* Add jest setup with global.crypto

* Bump ipfs to 0.60.2
The newest patch fixes "Agent is not a constructor" error introduced in one of the previous versions
ipfs/js-ipfs#3938

* IPFS initialization fix - pass pregenerated peerID's private key as 'init' options to create method

* CI replication test - increase number of entries

* Cleanup

* Upgate changelog

* Fix/replace find free port (#161)

* Changed library for getting ports

* Fix test utils import

* send message instead ids

* Close websocket connection (#167)

Co-authored-by: Emilia Marczyk <emilia.marczyk@rumblefish.pl>
Co-authored-by: Wiktor Sieprawski <wiktor.sieprawski@rumblefish.pl>
Co-authored-by: bartosz.chyra <bartosz.chyra@rumblefish.pl>
SgtPooki referenced this issue in ipfs/js-kubo-rpc-client Aug 18, 2022
Pulls in new ipjs which stubs files that require the node version of
modules.

Fixes #3938
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug A bug in existing code (including security flaws) P0 Critical: Tackled by core team ASAP
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

8 participants