Repo: https://github.com/vortextemporum/BoringBananasCompany

I added Infura node provider to the config.js

Deploying to Netlify using

yarn build

build dir: build

It works fine off my ubuntu 20.04 lts on wsl2 using localhost:3000 using yarn start or even localhost:5000 using yarn build, but for whatever reason, Netlify throws an error during runtime.

6:52:01 PM: ModuleNotFoundError: Module not found: Error: Can't resolve 'electron' in '/opt/build/repo/node_modules/swarm-js/node_modules/got'
6:52:01 PM: > Build error occurred
6:52:01 PM: Error: > Build failed because of webpack errors
6:52:01 PM:     at /opt/build/repo/node_modules/next/dist/build/index.js:15:924
6:52:01 PM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:6:584)
6:52:01 PM: error Command failed with exit code 1.

2 Answers 2


Recommend deleting the node modules folder. Build it again. it should resolve the error. It did for me. Hope it works.

  • So, how would that work exactly. If the .gitignore ignores uploading node_modules. Then Netlify would be deploying fresh node_modules every time a deploy is triggered. Oct 13, 2021 at 23:21

I'm running into the same issue. Netlify build fails whenever I import web3 into a NextJS page, ex:

import Web3 from "web3"

Getting that same error - 'Can't resolve 'electron'.

I'm guessing this has something to do with server vs client side rendering and web3 probably doesn't work with server side, which may be the default for Next. I am new to both Next and web3 though so this is taking me some time to figure out. Thanks.

  • agree with this, did you find the solution? I also get same issue I also have web3 imported Mar 9, 2022 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.