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
Webpack 5: Module not found: Can't resolve 'http' #998
Comments
You need to add Let me know if that helps or not. :) |
(forgot to mention you need to add it to the |
I got it working by 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. |
You should be able to create a similar config that will alias This is all adding Is your target web? It looks like it should pick them up in that case, but I’m not terribly familiar with WebPack. See: https://webpack.js.org/configuration/resolve/#resolvemainfields I would love to include it in the docs though, if you can find a way to avoid pulling in those dependencies (they are the long way around; geturl -> http -> fetch compared to browser-geturl -> fetch) |
(i.e. you shouldn’t need those polyfils because I’ve already implemented the functions as an alternate implementation for when the needed things being polyfilled don’t exist; you just need to let the bundler know they are there. ;)) |
hey @ricmoo ! I'm a little lost here too as I think Nextjs should already be adding "browser" to mainFields, so I don't know why Nextjs is still complaining. |
Since I'm doing only static browser builds, I updated my config with this to just not polyfill over the node modules for the server build. I -think- the client build is working as it should as it gets the mainFields>browser flag.
|
same issue here! |
I hit this issue to when I upgraded my project from Webpack v4 to v5. The fix was to prepend The webpack build was complaining about the
First I tried I setting The real solution was to fix the Fixing the imports also reduced my final bundle size considerably so this turned out to be a lucky error! |
i got it working using only this webpack resolve config: resolve: { aliasFields: ['browser', 'browser.esm'] } |
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. :) |
This should be addressed in 5.0.20. You should no longer need to specify Try it ou and let me know. Thanks! :) |
I'm hearing from various sources that these issues have been resolved, so I'm going to close this. Please re-open if you have any issues though. Thanks! :) |
Thanks! |
I'm using
|
this plugin automatically does the polyfill and worked for me. |
I'm importing ethersjs into my Nextjs SPA via
import { ethers } from "ethers";
and I'm getting the below error:Related to:
#349
The text was updated successfully, but these errors were encountered: