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.

javascript error: Cannot convert undefined or null to object

See original GitHub issue

Hey, after updating electron to v10 and spectron to v12 I’ve started having issues with running my test suite. So I started debugging by creating a single test with code taken from spectron’s readme. And when trying to run this test (I’m using Jest by the way) I get this error:

javascript error: javascript error: Cannot convert undefined or null to object
      (Session info: chrome=85.0.4183.98)

      at getErrorFromResponseBody (node_modules/webdriver/build/utils.js:121:10)
      at WebDriverRequest._request (node_modules/webdriver/build/request.js:149:56)
      at Browser.wrapCommandFn (node_modules/@wdio/utils/build/shim.js:74:23)
      at Browser.wrapCommandFn (node_modules/@wdio/utils/build/shim.js:74:23)

Application window launches however, the test fails

  • Node: v14.10.1
  • spectron: 12.0.0
  • electron: v10.1.2
  • chromedriver: 85.0.4183.98

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:25
  • Comments:23

github_iconTop GitHub Comments

12reactions
amiller-ghcommented, Dec 13, 2020

Tracked this one down I think.

Its an error from https://github.com/electron-userland/spectron/blob/1510a9beddb64ca3630c143ccdc15466e17b40f5/lib/api.js whose stack trace gets eaton by the bootstrap process.

Running it manually, we find the error is thrown here because electron.remote is undefined: https://github.com/electron-userland/spectron/blob/1510a9beddb64ca3630c143ccdc15466e17b40f5/lib/api.js#L141

As of Electron 10 enableRemoteModule defaults to false. It will be removed in v14. https://github.com/electron/electron/blob/master/docs/breaking-changes.md#default-changed-enableremotemodule-defaults-to-false

The fix for me was to explicitly enable it when creating my window in webPreferences:

const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
    },
  });

This should be updated in the getting started docs, and Spectron should migrate away from electron.remote if that’s not already planned 🙂

3reactions
TheOne20001commented, Sep 29, 2020

I have seen both of these. I have tried these two fixes but no luck there.

https://github.com/electron-userland/spectron/issues/174 https://github.com/electron-userland/spectron/issues/254

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot convert undefined or null to object - Stack Overflow
Generic answer. This error is caused when you call a function that expects an Object as its argument, but pass undefined or null...
Read more >
Cannot convert undefined or null to Object in JavaScript
The "Cannot convert undefined or null to Object" error occurs when we pass a null or an undefined value to a function that...
Read more >
Object.keys(null) possible - cannot convert undefined or null to ...
One possible solution is from this post https://stackoverflow.com/questions/74281137/companion-bubble-js-in-the-console. Looks like the Chrome ...
Read more >
Cannot convert undefined or null to object : r/learnjavascript
Your code throws the error because before fetch completes, location is undefined, but you are telling react to iterate over it, which can't...
Read more >
Cannot convert undefined or null to object ( But we didn't ...
Since this morning, we have this error message that appears (Cannot convert undefined or null to object). It is displayed when we want...
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