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

ReferenceError: Can't find variable: require #66

Closed
jerrygreen opened this issue Jan 21, 2020 · 2 comments
Closed

ReferenceError: Can't find variable: require #66

jerrygreen opened this issue Jan 21, 2020 · 2 comments

Comments

@jerrygreen
Copy link

jerrygreen commented Jan 21, 2020

This example works in electron, but it's broken when I open localhost:8888/home in browser. I see the following error in devtools console:

ReferenceError: Can't find variable: require
@saltyshiomix
Copy link
Owner

Hi @jerrygreen !
Thank you for your question.

Because NEXT's webpack config is optimized for electron like this:

// renderer/next.config.js
module.exports = {
  webpack: (config) => Object.assign(config, {
    target: 'electron-renderer',
  }),
};

So if you open the Chrome browser, you will get that errors because electron's browser is Chromium.

If you want to debug renderer (web) process in your browser, we must change next.config.js:

module.exports = {
  webpack: (config) => Object.assign(config, {
    // but this is not performant for Electron's browser
    target: 'web',
  }),
};

@jerrygreen
Copy link
Author

@saltyshiomix huh, just checked it, it indeed works. So it's a question of optimization... Thank you for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants