'Plugins' is deprecated. - Ionic Capacitor Background Task Implementation error

Today I was ready to write the blog about Background Task and give a sample project. But when I was creating the project I discovered that the use of capacitor- plugins has been changed. So here is what happened.

First, my project was not built. I tried ionic build and it was throwing the error :

because it is shown that:

Angular CLI requires a minimum node.js version of either v12.14 or v14.15.

So I upgraded the node JS.

After that as well when I tried to use Plugins

It was showing like :

First I did not understand what happened. I ignored the strike-through warning expecting errors to appear in the compilation.

"ionic build" command was successful this time

But "ionic cap run android --l --external" gave below result

After getting this error, I paid attention to the Plugin Part. So I commented out the plugin part, and tried to run the project and it was successful. So the problem was in the Plugin.

When I tried to go to the definition of Plugins( press F12), I got the below result.

(alias) const Plugins: PluginRegistry
import Plugins
@deprecated
Provided for backwards compatibility for Capacitor v2 plugins. Capacitor v3 plugins should import the plugin directly. This "Plugins" export is deprecated in v3, and will be removed in v4.

'Plugins' is deprecated.ts(6385)global.d.ts(5, 4): The declaration was marked as deprecated here.
Deprecated means not recommended to use because It is no longer being supported, It is obsolete. 'Plugins' is deprecated says Don't use 'Plugins'.
import type { WebPlugin } from './web-plugin';
export declare const Capacitor: import("./definitions").CapacitorGlobal;
export declare const registerPlugin: import("./definitions").RegisterPlugin;
/**
 * @deprecated Provided for backwards compatibility for Capacitor v2 plugins.
 * Capacitor v3 plugins should import the plugin directly. This "Plugins"
 * export is deprecated in v3, and will be removed in v4.
 */
export declare const Plugins: import(".").PluginRegistry;
/**
 * Provided for backwards compatibility. Use the registerPlugin() API
 * instead, and provide the web plugin as the "web" implmenetation.
 * For example
 *
 * export const Example = registerPlugin('Example', {
 *   web: () => import('./web').then(m => new m.Example())
 * })
 *
 * @deprecated Deprecated in v3, will be removed from v4.
 */
export declare const registerWebPlugin: (plugin: WebPlugin) => void;

So I went through the https://capacitorjs.com/docs/v2/apis/background-task and I found nothing new. But when I went to Github then I find below two posts:

https://github.com/capacitor-community/proposals/issues/108

https://github.com/ionic-team/capacitor/issues/3032

I find out on the second post that there is a new update, and there are many things changed in the v3 which you can find here:

https://capacitorjs.com/docs/updating/3-0

About the background Task:

Background Task: This plugin appeared to be rarely used and didn’t quite work as most devs expected. The core team will readdress background functionality in the future. Subscribe to #3032 for updates.

So If you are also trying to use background task and not able to implement it, This is the reason. 

On the capacitor community page, the existing solution is given 

 https://github.com/robingenz/capacitor-background-task

But I have not tried it yet. 

Hope this is helpful, Thank you.

 

 

 

 

Add comment