Having issue in creating cordova plugin and also having problem in importing it in ionic cordova project.

I want to create a cordova plugin in my local system but having issue while importing and installing it in my ionic cordova project, i am having error while trying to import the cordova plugin in ionic cordova project, so i want a solution that how i create a cordova project in my local system first then after testing will to publish it.
I am using below versions-
ionic -v
7.2.0
cordova -v
12.0.0 (cordova-lib@12.0.1)
npm -v
10.2.3
node -v
v18.19.0
nvm -v
1.1.11

Error -
Error:
Build at: 2024-01-29T14:45:00.196Z - Hash: 4798c2666d0154ce - Time: 1087ms
Error: src/app/home/home.page.ts:25:29 - error TS2307: Cannot find module ‘io.electrosoft.helloworld’ or its corresponding type declarations.
25 import HelloTestPlugin from ‘io.electrosoft.helloworld’;
import { HelloTestPlugin } from ‘io.electrosoft.helloworld’;
× Failed to compile.

Getting error in both ways, while importing the plugin.

I am having below files and folders in my cordova plugin
HelloTestPlugin\plugin.xml
HelloTestPlugin\src
HelloTestPlugin\src\android
HelloTestPlugin\src\android\HelloTestPlugin.java
plugin\HelloTestPlugin\www
HelloTestPlugin\www\HelloTestPlugin.js
HelloTestPlugin\package.json

I tried creating cordova plugin having below files in my cordova plugin -
HelloTestPlugin\plugin.xml
HelloTestPlugin\src
HelloTestPlugin\src\android
HelloTestPlugin\src\android\HelloTestPlugin.java
plugin\HelloTestPlugin\www
HelloTestPlugin\www\HelloTestPlugin.js
HelloTestPlugin\package.json

But not able to access and import this in my ionic cordova proejct.

I want to create a cordova plugin in my local system and after testing it then i want to publish it, I want to import that cordova project in my ionic cordova project for both android and ios platform.

Does your plugin have types?
did you export the HelloTestPlugin object in your types?

Yes, I created typings folder in my cordova plugin project-

HelloTestPlugin\typings\HelloTestPlugin.d.ts

declare module ‘io.electrosoft.helloworld’ {
export function coolMethod(arg0: any, success: Function, error: Function): void;
// Add other members if needed
}

import { HelloTestPlugin } from ‘io.electrosoft.helloworld’;

Error-

Build at: 2024-02-06T13:00:50.837Z - Hash: d7ce281a36118e3f - Time: 807ms

Error: src/app/home/home.page.ts:25:29 - error TS2307: Cannot find module ‘io.electrosoft.helloworld’ or its corresponding type declarations.

25 import HelloTestPlugin from ‘io.electrosoft.helloworld’;

‘HelloTestPlugin’ is declared but its value is never read.ts(6133)

Module ‘“io.electrosoft.helloworld”’ has no exported member ‘HelloTestPlugin’.ts(2305)

import HelloTestPlugin

Please let me know if anything you need to know about the plugin code.
Thank you.

Those typings don’t look correct, you are exporting only coolMethod, but trying to import HelloTestPlugin, which is not exported.

I’m not very familiar with types in Cordova plugins, so I can’t help you more than that.

Okay, i will check it, Thank you for the help.

In my cordova plugin -
HelloTestPlugin\typings\HelloTestPlugin.d.ts

declare module ‘io.electrosoft.helloworld’ {
export function coolMethod(arg0: any, success: Function, error: Function): void;
}

in my ionic cordova project i imported it-

import { coolMethod } from ‘io.electrosoft.helloworld’;

but still i am getting below error-
./src/app/home/home.page.ts:28:0-66 - Error: Module not found: Error: Can’t resolve ‘io.electrosoft.helloworld’ in ‘D:\myCordovaApp\src\app\home’
[ng]
[ng] Error: src/app/home/home.page.ts:42:39 - error TS2307: Cannot find module ‘io.electrosoft.helloworld’ or its corresponding type declarations.
[ng]
[ng] 42 import { coolMethod } from ‘io.electrosoft.helloworld’;
[
[ng]
[ng] × Failed to compile.

The plugin is in my local system i didn’t publish it, I install the plugin in my ionic cordova plugin like this

ionic cordova plugin add “D:/plugin/HelloTestPlugin”

npm install “D:/plugin/HelloTestPlugin”

Please let me know if you know how to fix it. Thank you