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

packages/ipfs-core/src/index.js attempts to export undefined Buffer #3312

Closed
georgyo opened this issue Oct 5, 2020 · 1 comment · Fixed by #3348
Closed

packages/ipfs-core/src/index.js attempts to export undefined Buffer #3312

georgyo opened this issue Oct 5, 2020 · 1 comment · Fixed by #3348
Labels
need/triage Needs initial labeling and prioritization

Comments

@georgyo
Copy link
Contributor

georgyo commented Oct 5, 2020

  • Version:
    Problem exists from at least 50.1, but is on master as well.

Severity:

High - The main functionality of the application does not work, API breakage, repo format breakage, etc.

Description:

Loading code that is browserified will cause js-ipfs to fail to load with the following error

[ipfs-provider] ReferenceError: Buffer is not defined
    at Object.669../api-manager (index.js:125)
    at o (_prelude.js:1)
    at _prelude.js:1
    at loadJsIpfsModule (index2.js:8)
    at tryJsIpfs (js-ipfs.js:12)
    at index.js:37
    at index.js:24
    at Object.getIpfs (index.js:52)
    at async HTMLDocument.<anonymous> (index2.js:6)

Steps to reproduce the error:

browserify the following code and including it in any browser will show the error

'use strict'

const IpfsProvider = require('ipfs-provider')

document.addEventListener('DOMContentLoaded', async () => {
    const { ipfs, provider, apiAddress } = await IpfsProvider.getIpfs({
    loadHttpClientModule: () => require('ipfs-http-client'),
    loadJsIpfsModule: () => require('ipfs'),
    providers: [ 
      IpfsProvider.providers.windowIpfs({permissions: { commands: ['cat'] }}),
      IpfsProvider.providers.jsIpfs(),
      IpfsProvider.providers.httpClient(),
      IpfsProvider.providers.httpClient({apiAddress: "https://gateway.ipfs.io:443" })
    ]
    })
      console.log('IPFS API is provided by: ' + provider + ' with address: ' + apiAddress)
      window.ipfs = ipfs
})

Even beyond that, just looking at the current code clearly shows a that Buffer is in module.exports but is not defined anywhere else: https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-core/src/index.js

@georgyo georgyo added the need/triage Needs initial labeling and prioritization label Oct 5, 2020
@jacobheun
Copy link
Contributor

We should remove the export in the upcoming minor release

achingbrain added a commit that referenced this issue Oct 26, 2020
Everything is Uint8Arrays now so there's no need to export node's
Buffer module any more.

Fixes #3312

BREAKING CHANGE: `Buffer` is no longer exported from core
achingbrain added a commit that referenced this issue Oct 27, 2020
Everything is Uint8Arrays now so there's no need to export node's
Buffer module any more.

Fixes #3312

BREAKING CHANGE: `Buffer` is no longer exported from core
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants