mhartington / cordova-config-utils

32 stars 5 forks source link

net.js: throw new TypeError('invalid data') #18

Open biesbjerg opened 8 years ago

biesbjerg commented 8 years ago

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?

biesbjerg commented 8 years ago

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) {
biesbjerg commented 8 years ago

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 lodash@4.14.0, 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
├─┬ cordova-config-utils@2.3.0
│ └── lodash@4.14.0
├─┬ gulp@3.9.1
│ └─┬ vinyl-fs@0.3.14
│   └─┬ glob-watcher@0.0.6
│     └─┬ gaze@0.5.2
│       └─┬ globule@0.1.0
│         └── lodash@1.0.2
├─┬ ionic-angular@2.0.0-beta.10
│ └── lodash@3.10.1
└─┬ ionic-gulp-sass-build@1.0.0
  └─┬ gulp-sass@2.3.2
    └─┬ node-sass@3.8.0
      ├─┬ gaze@1.1.0
      │ └─┬ globule@1.0.0
      │   └── lodash@4.9.0
      └─┬ sass-graph@2.1.2
        └── lodash@4.14.0
nerdoza commented 8 years ago

Same issue for me.

krik commented 8 years ago

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. :(

vegmorse commented 7 years ago

I fix the issue adding a peerDependencies in package.json

"peerDependencies": { "lodash": "^4.16.0" },

hope i help you

jordan-schneider commented 6 years ago

I had to use parent="application" instead of "/manifest/application" for whatever reason. I wouldn't have know this without the change in #20 .