Skip to content
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

ModuleNotFoundError: Module not found: Error: Can't resolve 'electron' #2696

Closed
rtscosta opened this issue Apr 11, 2022 · 10 comments
Closed
Labels
archived This issue has been locked.

Comments

@rtscosta
Copy link

Hi guys. I am trying to use Amplify with a React / Next / web3 project. When I tried to build the project, I got the following error on the Frontend build part.

Does any have this erro before or know how to solve it?

2022-04-10T03:00:11.543Z [ERROR]: Error: Command failed with exit code 1: node_modules/.bin/next build
warn - No ESLint configuration detected. Run next lint to begin setup
Failed to compile.
ModuleNotFoundError: Module not found: Error: Can't resolve 'electron' in '/codebuild/output/src624730322/src/taskReward/node_modules/swarm-js/node_modules/got'
> Build error occurred
Error: > Build failed because of webpack errors
at /codebuild/output/src624730322/src/taskReward/node_modules/next/dist/build/index.js:397:19
at async Span.traceAsyncFn (/codebuild/output/src624730322/src/taskReward/node_modules/next/dist/telemetry/trace/trace.js:60:20)
at async Object.build [as default] (/codebuild/output/src624730322/src/taskReward/node_modules/next/dist/build/index.js:77:25)

@austinpickett
Copy link

Running into this issue as well- builds fine on Vercel...

@calavera
Copy link
Contributor

It looks like got doesn't support electron anymore, but somehow your application is using it. You're probably bumping into this issue because you're requiring that library without being present in your node modules.

@austinpickett
Copy link

austinpickett commented Apr 26, 2022

@calavera thx for the reply, below is the log where the issue appears:

2022-04-26T16:58:26.215Z [INFO]: Starting SSR Build...
2022-04-26T16:59:57.758Z [ERROR]: Error: Command failed with exit code 1: node_modules/.bin/next build
                                  warn  - The `target` config is deprecated and will be removed in a future version.
                                  See more info here https://nextjs.org/docs/messages/deprecated-target-config
                                  Failed to compile.
                                  ./node_modules/swarm-js/node_modules/got/index.js
                                  Module not found: Can't resolve 'electron' in '/codebuild/output/src722649380/src/redacted/web/node_modules/swarm-js/node_modules/got'
                                  Import trace for requested module:
                                  ./node_modules/swarm-js/lib/files.js
                                  ./node_modules/swarm-js/lib/api-node.js
                                  ./node_modules/web3-bzz/lib/index.js
                                  ./node_modules/web3/lib/index.js

web3 uses swarm, swarm uses got, got is requiring electron -- a nasty rabbit hole. The curious part of it is it builds locally just fine, and builds on vercel just fine.

The issue is somewhere with how Amplify is building the SSR module.

@austinpickett
Copy link

@rtscosta this shows a solution to ignore the deprecated package via webpack/nextjs config: sindresorhus/got#345

@calavera
Copy link
Contributor

yeah, that sounds like a problem with implicit dependencies. Something installs the electron package in your local system, or Vercel, but not in Amplify. Then webpack tries to import the plugin, and it doesn't work because the implicit dependency is not there 🤔

@rtscosta this is the change you need in your webpack configuration to avoid this problem:

module.exports = {
    plugins: [
        new webpack.IgnorePlugin({
            resourceRegExp: /^electron$/
        }),
    ]
}

@en3sis
Copy link

en3sis commented May 8, 2022

Did you manage to solve it? @rtscosta ?
I'm having the same scenario and it's super annoying. I still don't understand why it would compile on one side and not the other.

I tried with next.config.js

module.exports = {
  webpack: (config, { webpack }) => {
    config.plugins.push(new webpack.IgnorePlugin({
      resourceRegExp: /^electron$/
    }));
  }
}

Does not seems to help.

@itseasy21
Copy link

@en3sis you need to return config as well then only it'll work.

Update your code to this and it should start working:

webpack: (config, { webpack }) => {
		config.plugins.push(
			new webpack.IgnorePlugin({
				resourceRegExp: /^electron$/,
			})
		);
		return config;
	},

@ghost ghost closed this as completed Aug 13, 2022
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@rtscosta
Copy link
Author

rtscosta commented Oct 11, 2022 via email

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot added the archived This issue has been locked. label Oct 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived This issue has been locked.
Projects
None yet
Development

No branches or pull requests

5 participants