Deprecation of injectCapacitor method

There is currently a warning, followed by an error, when Electron is executed after the build:

WARNING: injectCapacitor method is deprecated and will be removed in next major release. Check release notes for mi
gration instructions

    at getURLFileContents (C:\Users\mando\Projects\\r2\electron\node_modules\@capacitor\electron\index.js:
    at injectCapacitor (C:\Users\mando\Projects\\r2\electron\node_modules\@capacitor\electron\index.js:20:
    at Timeout._onTimeout (C:\Users\mando\Projects\\r2\electron\node_modules\@capacitor\electron\index.js:
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

After some debugging, I discovered that if I changed this line in ./electron/index.js from init(inject = true) to init(inject = false), then it works fine.

Then I found that this is the fix is already in place in the Github repo, but has not yet been released.

So two questions:

  • when will this fix be released to NPM?
  • any advice on a work-around in the meantime?

The change needs to be done on the user app, it’s been released since Capacitor 1.1.0, but only apply to new apps (or apps that add electron for the first time)
There is an update guide you can follow
or if you didn’t make any change inside electron folder, you can always remove the folder and run npx cap add electron again, but changes are very simple.

1 Like