Invalid package.json in Custom cordova plugin

I had the same issue, but used this npm init instead, press Enter and fill in the data as asked on the cmd


I meet the same 'pkg is not defined' problem, then I try to use npm init to create package.json file and succeed.


I got the same error.

Following the reasoning in this answer I've realized that when we try to install a cordova plugin from a folder: The name of target folder must be the same of plugin ID


I had same issue while adding my custom plugin to project. I am using plugman tool to create custom plugin and you may most probably be using plugman tool too.

If that is the case then execute following command to generate valid package.json:

plugman createpackagejson "path of your plugin"

This will ask you some basic question about plugin and will generate package.json file based on it.