question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack 5: Module not found: Can't resolve 'http'

See original GitHub issue

I’m importing ethersjs into my Nextjs SPA via import { ethers } from "ethers"; and I’m getting the below error:

error - ./node_modules/@ethersproject/web/lib.esm/geturl.js:11:0
Module not found: Can't resolve 'http'

Related to: https://github.com/ethers-io/ethers.js/issues/349

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

9reactions
jadboxcommented, Aug 13, 2020

I got it working by yarn install http-browserify https-browserify and updating next.config.js to the below:

module.exports = {
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    config.resolve.alias.https = "https-browserify";
    config.resolve.alias.http = "http-browserify";
    return config;
  },
};

It would be great if this was documented or have a simpler method to define the needed polyfills, as I’d imagine other developers will face the same problem upgrading to webpack 5.

2reactions
ricmoocommented, Nov 3, 2020

Wow. I didn’t know you could specify non-standard fields. :p

That field is meant more as an internal build system flag.

I have a new build system nearly done which should make everything cooperate with webpack/rollup/etc. much better without these hacks… It’s coming. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 Errors - Cannot Resolve 'crypto', 'http', and 'https' in ...
I have created a new React project using npx create-react-app client and have encountered some issues with Webpack 5. Originally, I had errors ......
Read more >
Module not found: Error: Can't resolve 'http' [Solved] | bobbyhadz
The error "Module not found: Error: Can't resolve 'http'" occurs because there has been a breaking change in Webpack version 5. To solve...
Read more >
Webpack 5 errors | ImmutableX Documentation
Module not found : Error: Can't resolve 'https' in '/Users/{username}/{project-name}/node_modules/@imtbl/imx-sdk/dist' BREAKING CHANGE: webpack < 5 used to ...
Read more >
Resolve | webpack
For example, when calling import 'lodash' in ES2015, the resolve options can ... Webpack 5 no longer polyfills Node.js core modules automatically which ......
Read more >
[SOLVED] Im facing issues installing moralis in my app ...
Module not found : Error: Can't resolve 'http' in ... BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found