Cordova安装自定义插件时遇Cannot read property 'fail' of undefined错误
I’ve run into this exact error before when working with custom Cordova plugins, so let’s break down what’s happening and walk through fixes step by step.
First, let’s recap your scenario:
You’re trying to install a custom plugin using this plugman command:
plugman -d install --platform android --project platforms\android --plugin plugins\PrintName
And you’re hitting this TypeError:
TypeError: Cannot read property 'fail' of undefined
at C:...\AppData\Roaming\npm\node_modules\plugman\node_modules\cordova-lib\src\plugman\fetch.js:168:18
at _fulfilled (C:...\AppData\Roaming\npm\node_modules\plugman\node_modules\q\q.js:787:54)
at self.promiseDispatch.done (C:...\AppData\Roaming\npm\node_modules\plugman\node_modules\q\q.js:816:30)
at Promise.promise.promiseDispatch (C:...\AppData\Roaming\npm\node_modules\plugman\node_modules\q\q.js:749:13)
at C:...\AppData\Roaming\npm\node_modules\plugman\node_modules\q\q.js:509:49
at flush (C:...\AppData\Roaming\npm\node_modules\plugman\node_modules\q\q.js:108:17)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:686:11)
at startup (bootstrap_node.js:187:16)
This error usually ties to path issues, invalid plugin metadata, or bugs in plugman’s dependency libraries. Here’s how to troubleshoot:
Fix path formatting for Windows
Windows can struggle with backslashes in paths. Try replacing them with forward slashes in your command:plugman -d install --platform android --project platforms/android --plugin plugins/PrintNameAlso double-check that the
plugins/PrintNamedirectory actually exists and contains all your plugin files (no missing folders or core files).Validate your plugin’s configuration files
The error happens during the fetch phase, meaning plugman can’t parse your plugin’s metadata correctly:- Make sure your plugin has a valid
plugin.xmlin its root. Verify the root<plugin>tag includes required attributes likeid,version, andname. - If your plugin uses a
package.json, confirm it’s properly formatted (no missing commas, valid npm fields likenameandversion). You can runnpm validatein the plugin directory to check for issues.
- Make sure your plugin has a valid
Update or roll back plugman
This specific error has been linked to buggy versions ofcordova-lib(used by plugman). Try updating to the latest stable version:npm install -g plugmanIf updating doesn’t work, roll back to a known stable version (e.g., 3.0.0):
npm install -g plugman@3.0.0Clear cache and reinstall plugman
Corrupted cache can cause unexpected glitches. Reset your npm cache and reinstall plugman:npm cache clean --force npm uninstall -g plugman npm install -g plugmanSwitch to the native Cordova install command
Sometimes the standard Cordova plugin command avoids plugman-specific bugs. Give this a try:cordova plugin add ./plugins/PrintName --platform android
内容的提问来源于stack exchange,提问作者Krups

