diff --git a/CHANGELOG.md b/CHANGELOG.md index 024c9dc2b29..1b4c25a8d74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -617,3 +617,4 @@ Released with 1.0.0-beta.37 code base. ### Fixed - Fixed types for `web3.utils._jsonInterfaceMethodToString` (#5550) +- Fixed Next.js builds failing on Node.js v16, Abortcontroller added if it doesn't exist globally (#5601) \ No newline at end of file diff --git a/packages/web3-providers-http/src/index.js b/packages/web3-providers-http/src/index.js index 4169ed62a38..44bd193a0c4 100644 --- a/packages/web3-providers-http/src/index.js +++ b/packages/web3-providers-http/src/index.js @@ -30,7 +30,11 @@ var https = require('https'); // Apply missing polyfill for IE require('cross-fetch/polyfill'); require('es6-promise').polyfill(); -require('abortcontroller-polyfill/dist/polyfill-patch-fetch'); + +// import abortController if abortController is not included in node +if(typeof global !== "undefined" && !global.AbortController){ + require('abortcontroller-polyfill/dist/polyfill-patch-fetch') +} /** * HttpProvider should be used to send rpc calls over http diff --git a/test/httpprovider.js b/test/httpprovider.js index 162e294a9d6..6814b92bba3 100644 --- a/test/httpprovider.js +++ b/test/httpprovider.js @@ -71,10 +71,12 @@ describe('web3-providers-http', function () { describe('send', function () { it('should fail with invalid remote node connection', async function () { + var provider = new HttpProvider('http://localhost:8545'); var web3 = new Web3(provider); await expect(web3.eth.getChainId()).to.be.rejectedWith(Error, "CONNECTION ERROR: Couldn't connect to node http://localhost:8545."); + }); it('should fail for non-json format response', async function () {