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.

require is not defined

See original GitHub issue

Describe the bug When I import custom-electron-titlebar, I get an Uncaught ReferenceError: require is not defined error in devtools.

|> Uncaught ReferenceError: require is not defined ------------ external “electron”:1 at Object.electron (external “electron”:1) at webpack_require (bootstrap:789) at fn (bootstrap:100) at Object…/node/modules/custom-electron-titlebar/lib/menubar.js (menubar.js:12) at webpack_require (bootstrap:789) at fn (bootstrap:100) at Object…/node/modules/custom-electron-titlebar/lib/titlebar.js (titlebar.js:15) at webpack_require (bootstrap:789) at fn (bootstrap:100) at Object…/node/modules/custom-electron-titlebar/lib/index.js (index.js:15)

To Reproduce Steps to reproduce the behavior: I’ve commited a few different options on my project, so you can see exactly what I’m adding and where. (sorry, even the “working” version is ugly, debugging, JSON.stringify stuff)

Here’s the commit that’s currently working properly. Here’s the commit with import { Titlebar, Color } from ‘custom-electron-titlebar’ added to renderer.js

Expected behavior I expected these lines to add a custom title bar.

Desktop (please complete the following information):

  • OS: [Windows]
  • Electron version [8.0.0]
  • Node Version [v12.15.0]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
Fraasicommented, Jan 11, 2021

Electron is patching up some security holes and nodeintegration is no longer recommended. I got around this require/import problem by initiating titlebar in my preload script , works nicely in my use case. see this and this for more info.

const { Titlebar } = require('custom-electron-titlebar');

window.addEventListener('DOMContentLoaded', () => {
  new Titlebar({
    //  settings...
  })
})
1reaction
GypsyDangerouscommented, Jul 13, 2020

try window.require

Read more comments on GitHub >

github_iconTop Results From Across the Web

Client on Node.js: Uncaught ReferenceError: require is not ...
However, require is not defined on the client side, and it throws an error of the form Uncaught ReferenceError: require is not defined...
Read more >
ReferenceError: require is not defined in JavaScript - Stack Diary
The "ReferenceError: require is not defined" error occurs when the require function is used in a JavaScript file that is intended to be ......
Read more >
How to fix "require is not defined" in JavaScript / Node.js?
In our case, the error message is “require is not defined” which indicates the problem is with the variable or method named “require”....
Read more >
How To Fix ReferenceError require is not defined in JavaScript
The Solution. Your ReferenceError: require is not defined likely has one of two causes: You tried using require in a browser environment ......
Read more >
Fix "require is not defined" in JavaScript/Node - Stack Abuse
You try to use the require statement in the browser · You try to use require in Node when ES modules are specified...
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