cordova-config-utils
cordova-config-utils copied to clipboard
net.js: throw new TypeError('invalid data')
I copied the example for adding a config-file
section for Android into my config.xml and ran ionic build ios
Output:
bash-3.2$ ionic build android
Running 'build:before' gulp task before build
[05:36:41] Starting 'clean'...
[05:36:42] Finished 'clean' after 47 ms
[05:36:42] Starting 'build'...
[05:36:42] Starting 'sass'...
[05:36:42] Starting 'html'...
[05:36:42] Starting 'fonts'...
[05:36:42] Starting 'config'...
[05:36:42] Starting 'scripts'...
[05:36:42] Finished 'config' after 65 ms
[05:36:42] Finished 'scripts' after 82 ms
[05:36:42] Finished 'fonts' after 101 ms
[05:36:42] Finished 'html' after 109 ms
[05:36:43] Finished 'sass' after 1.03 s
[05:36:55] Finished 'build' after 13 s
[05:36:55] Starting 'build:before'...
[05:36:55] Finished 'build:before' after 10 μs
Running command: /Users/kim/ionic/MindlyApp/hooks/after_prepare/010_add_platform_class.js /Users/kim/ionic/MindlyApp
add to body class: platform-android
Running command: /Users/kim/ionic/MindlyApp/hooks/after_prepare/011_update_config.js /Users/kim/ionic/MindlyApp
net.js:641
throw new TypeError('invalid data');
^
TypeError: invalid data
at Socket.write (net.js:641:11)
at /Users/kim/ionic/MindlyApp/hooks/after_prepare/011_update_config.js:319:24
at arrayEach (/Users/kim/ionic/MindlyApp/node_modules/lodash/index.js:1289:13)
at Function.<anonymous> (/Users/kim/ionic/MindlyApp/node_modules/lodash/index.js:3345:13)
at /Users/kim/ionic/MindlyApp/hooks/after_prepare/011_update_config.js:314:7
at Object.<anonymous> (/Users/kim/ionic/MindlyApp/hooks/after_prepare/011_update_config.js:323:3)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
Error: Hook failed with error code 1: /Users/kim/ionic/MindlyApp/hooks/after_prepare/011_update_config.js
Caught exception:
undefined
Is it a bug or am I doing something wrong?
A bit of debugging reveals that config-file is read correctly:
[{
"_id": 27,
"tag": "config-file",
"attrib": {
"target": "AndroidManifest.xml",
"parent": "/*"
},
"text": "\n ",
"tail": "\n ",
"_children": [{
"_id": 28,
"tag": "supports-screens",
"attrib": {
"android:xlargeScreens": "false",
"android:largeScreens": "false",
"android:smallScreens": "false"
},
"text": "",
"tail": "\n ",
"_children": []
}, {
"_id": 29,
"tag": "uses-permission",
"attrib": {
"android:name": "android.permission.READ_CONTACTS",
"android:maxSdkVersion": "15"
},
"text": "",
"tail": "\n ",
"_children": []
}, {
"_id": 30,
"tag": "uses-permission",
"attrib": {
"android:name": "android.permission.WRITE_CONTACTS"
},
"text": "",
"tail": "\n ",
"_children": []
}]
}]
But for some reason _.keyBy
throws an Error
getConfigFilesByTargetAndParent: function(platform) {
var configFileData = this.getConfigXml().findall('platform[@name=\'' + platform + '\']/config-file');
return _.keyBy(configFileData, function(item) {
Maybe it's the lodash version's fault?
/**
* @license
* lodash 3.10.1 (Custom Build) <https://lodash.com/>
* Build: `lodash modern -d -o ./index.js`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <https://lodash.com/license>
*/
I see the cordova-config-utils package depends on [email protected], but somehow another (older) version is required
in the hook - any idea how to fix this?
bash-3.2$ npm list lodash
Mindly@ /Users/kim/ionic/MindlyApp
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│ └─┬ [email protected]
│ └─┬ [email protected]
│ └─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└─┬ [email protected]
└─┬ [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
└── [email protected]
Same issue for me.
This happens if you have an older lodash version as a top-level dependency of your package. Because the hook is copied out of node_modules hierarchy and into hooks it is then requiring the older top-level version of lodash and and not it's own nested dependency.
Not sure how to fix this though. :(
I fix the issue adding a peerDependencies in package.json
"peerDependencies": { "lodash": "^4.16.0" },
hope i help you
I had to use parent="application" instead of "/manifest/application" for whatever reason. I wouldn't have know this without the change in #20 .