spectron: javascript error: Cannot convert undefined or null to object

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

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 25
  • Comments: 23

Most upvoted comments

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 🙂

Any updates on this?

First time I try to use Spectron - and using the readme example - I do get the same error as others have mentionned:

javascript error: javascript error: Cannot convert undefined or null to object (Session info: chrome=85.0.4183.121) at getErrorFromResponseBody (node_modules\webdriver\build\utils.js:121:10) at WebDriverRequest._request (node_modules\webdriver\build\request.js:149:56) at processTicksAndRejections (internal/process/task_queues.js:93:5) at async Browser.wrapCommandFn (node_modules@wdio\utils\build\shim.js:74:23) at async Browser.wrapCommandFn (node_modules@wdio\utils\build\shim.js:74:23)

@amiller-gh This is correct. Remote module was missing. I enable it during tests now.

This didn’t solve it for me - I actually already tried this a few months ago.