javascript error: Cannot convert undefined or null to object
See original GitHub issueHey, 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:
- Created 3 years ago
- Reactions:25
- Comments:23
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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#L141As of Electron 10
enableRemoteModule
defaults tofalse
. It will be removed in v14. https://github.com/electron/electron/blob/master/docs/breaking-changes.md#default-changed-enableremotemodule-defaults-to-falseThe fix for me was to explicitly enable it when creating my window in
webPreferences
:This should be updated in the getting started docs, and Spectron should migrate away from electron.remote if that’s not already planned 🙂
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