cordova plugin add: "Unexpected end of JSON input"
Closed this issue · 6 comments
Bug Report
Problem
What is expected to happen?
Plugins can be added using the "cordova plugin add" command
What does actually happen?
A single line of output is displayed: "Unexpected end of JSON input"
Information
I've tracked this issue to cordova-lib/src/cordova/plugin/util.js
, in the "info" function. The call to execa("npm", ...
) is returning no output. However, this doesn't seem to be an issue with "execa" because other calls such as "ls" are returning output fine.
If you change that line to the following:
return execa('bash', ['-c', `cat <(npm ${viewArgs.join(' ')})`])
Then it works. So I suspect it's something weird with npm or node's behaviour, not flushing to stdout or something like that.
Command or Code
npx cordova plugin add cordova-plugin-device
Environment, Platform, Device
Ubuntu 22.04.2
Version information
"node" Snap 18.16.1 (Rev 7588)
Node 18.16.1
NPM 9.5.1
Cordova 12.0.0
Checklist
- I searched for existing GitHub issues
- I updated all Cordova tooling to most recent version
- I included all the necessary information above
Sorry, to say the changed lined "works" wasn't correct. This output comes back:
{
"_id": "cordova-plugin-device@2.1.0",
"_rev": "86-bc3d7f958bc2997ad32582693ea2ddff",
"name": "cordova-plugin-device",
"description": "Cordova Device Plugin",
"dist-tags": {
"latest": "2.1.0"
},
"versions": [
"0.2.1",
"0.2.3",
"0.2.4",
"0.2.5",
"0.2.6",
"0.2.7",
"0.2.8",
"0.2.9",
"0.2.10",
"0.2.11",
"0.2.12",
"0.2.13",
"0.3.0",
"1.0.0",
"1.0.1",
"1.1.0",
"1.1.1",
"1.1.2",
"1.1.3",
"1.1.4",
"1.1.5",
"1.1.6",
"1.1.7",
"2.0.0",
"2.0.1",
"2.0.2",
"2.0.3",
"2.1.0"
],
"maintainers": [
"brodybits <chris.brody+brodybits@gmail.com>",
"dpogue <darryl@dpogue.ca>",
"cordovaowner <apachecordovabot@gmail.com>",
"stevegill <stevengill97@gmail.com>",
"purplecabbage <purplecabbage@gmail.com>",
"anis <anis.kadri@gmail.com>",
"filmaj <maj.fil@gmail.com>",
"bowserj <bowserj@apache.org>",
"shazron <shazron@gmail.com>",
"surajpindoria <pindoria.suraj@gmail.com>",
"erisu <erisu.dev@outlook.jp>",
"niklasmerz <NiklasMerz@gmx.net>",
"janpio <piotrowski+npm@gmail.com>",
"normanbreau <norman@nbsolutions.ca>",
"pvpoyer <pieter.vanpoyer@portofantwerp.com>",
"csantanapr <csantana23@gmail.com>",
"macdonst <simon.macdonald@gmail.com>",
"jcesarmobile <jcesarmobile@gmail.com>"
],
"time": {
"modified": "2022-06-14T00:04:36.572Z",
"created": "2015-01-23T00:59:37.520Z",
"0.2.13": "2015-01-23T00:59:37.520Z",
"0.2.1": "2015-02-25T07:51:07.844Z",
"0.2.10": "2015-02-25T07:51:09.339Z",
"0.2.11": "2015-02-25T07:51:10.644Z",
"0.2.12": "2015-02-25T07:51:11.844Z",
"0.2.3": "2015-02-25T07:51:14.331Z",
"0.2.4": "2015-02-25T07:51:15.827Z",
"0.2.5": "2015-02-25T07:51:17.381Z",
"0.2.6": "2015-02-25T07:51:18.697Z",
"0.2.7": "2015-02-25T07:51:19.958Z",
"0.2.8": "2015-02-25T07:51:21.465Z",
"0.2.9": "2015-02-25T07:51:23.170Z",
"0.3.0": "2015-02-25T07:51:24.411Z",
"1.0.0": "2015-04-21T22:26:51.411Z",
"1.0.1": "2015-06-22T23:09:26.268Z",
"1.1.0": "2015-11-24T23:36:41.966Z",
"1.1.1": "2016-01-20T01:26:50.773Z",
"1.1.2": "2016-04-20T22:06:55.408Z",
"1.1.3": "2016-09-15T01:05:17.413Z",
"1.1.4": "2016-12-12T18:41:04.207Z",
"1.1.5": "2017-03-08T00:55:52.302Z",
"1.1.6": "2017-05-02T00:42:00.931Z",
"1.1.7": "2017-11-11T00:54:22.691Z",
"2.0.0": "2017-12-20T18:39:06.667Z",
"2.0.1": "2017-12-31T03:26:38.263Z",
"2.0.2": "2018-04-17T06:06:29.580Z",
"2.0.3": "2019-07-02T17:41:31.854Z",
"2.1.0": "2022-04-11T01:57:26.025Z"
},
"keywords": [
"cordova",
"device",
"ecosystem:cordova",
"cordova-android",
"cordova-electron",
"cordova-ios",
"cordova-windows",
"cordova-browser",
"cordova-osx"
],
"repository": "github:apache/cordova-plugin-device",
"author": "Apache Software Foundation",
"license": "Apache-2.0",
"readmeFilename": "",
"users": {
"cnring18": true,
"flotage": true,
"babakarj": true,
"nexxtmobile": true,
"xueboren": true,
"isik": true,
"perlish": true,
"jimmytiger": true,
"plesh": true,
"stuartbarstock": true,
"trenthm": true,
"danail": true,
"aesinv": true,
"antjw": true,
"sjlee4520": true,
"bgqkl": true,
"jonathancoradi": true,
"dspjm": true,
"lonerdottie": true,
"mutantodon": true,
"lordkbx": true,
"shanewholloway": true,
"jorn": true,
"robhart": true,
"yuch4n": true,
"chinawolf_wyp": true,
"pendo.praetoriani": true,
"corenpro": true,
"desertcrystal": true,
"atakane": true,
"alexreg90": true,
"alexreg": true,
"npm-packages": true
},
"bugs": "https://github.com/apache/cordova-plugin-device/issues",
"_contentLength": 59196,
"version": "2.1.0",
"types": "./types/index.d.ts",
"cordova": {
"id": "cordova-plugin-device",
"platforms": [
"android",
"electron",
"ios",
"windows",
"browser",
"osx"
]
},
"scripts": {
"test": "npm run lint",
"lint": "eslint ."
},
"engines": {
"cordovaDependencies": {
"3.0.0": {
"cordova": ">100",
"cordova-electron": ">=3.0.0"
}
}
},
"devDependencies": {
"@cordova/eslint-config": "^3.0.0"
},
"_integrity": "sha512-FU0Lw1jZpuKOgG4v80LrfMAOIMCGfAVPumn7AwaX9S1iU/X3OPZUyoKUgP09q4bxL35IeNPkqNWVKYduAXZ1sg==",
"_resolved": "/Users/erisu/release/cordova/cordova-dist/plugins/cordova-plugin-device-2.1.0.tgz",
"_from": "file:cordova-dist/plugins/cordova-plugin-device-2.1.0.tgz",
"_nodeVersion": "16.14.2",
"_npmVersion": "8.5.0",
"dist": {
"integrity": "sha512-FU0Lw1jZpuKOgG4v80LrfMAOIMCGfAVPumn7AwaX9S1iU/X3OPZUyoKUgP09q4bxL35IeNPkqNWVKYduAXZ1sg==",
"shasum": "ef2292c2f0a34d01b5aca6c39cf204e48a460fb2",
"tarball": "https://registry.npmjs.org/cordova-plugin-device/-/cordova-plugin-device-2.1.0.tgz",
"fileCount": 18,
"unpackedSize": 69945,
"signatures": [
{
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
"sig": "MEYCIQCACHmJJ80XBtOOXRvjypNFR8azqnWAVKfgNbMxjUlldAIhAKxTcUSlgDyw0IclXJ0HkdyYUCPL1bH2gBktby4tx6sG"
}
],
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiU4sGACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq/kRAAiiEMzO1eTL9xOrTVhI6OhaSbrpuGxWK2cPHdGuB5zJ/BtHqS\r\njN8ybi4z0QB2aTob6wWdcWFdV5adtzYUtBAfZ0Jv68+yO5N1xmT3he1xxIpT\r\nxbG2sJG2ZHEIAwAyFP
qgXwUD9aPgTAyv8h1FQjgITx+V6+LHL1VD7HoGPqgk\r\n8DY57nsfya3vyDf/jY1GSXAzXK207qrgkaIT86fHnVHy62wj0AMT22IxZOEj\r\n2RTijyo9aMi69cPopLvRT3UU6ZyFM+afLVwiu7edLs+O9E7OinUli4nev/eK\r\nt/D8f/i2HpX+Nn0h7ASLBkjeXP4Ktb07qthEp1Hl3N4af/vHdDIrTmaL6P1I\r\nO
d45ZLnF2jvkvj/Mb3WUYXCkLCojIWq+a/j4lF3Ouw2QyLBdwBOaZeFkPsOa\r\nmh3BJbX3N6mnxiCz7iO9eUgwTDemnXz5tggJIs1ro6O1WcRbsA4vWxgaQ98V\r\nCSb3TMze/5dmad8yKjUgd0gZ6+kNkpH3tE+66bRRLVCJ6GZCgozNJH/I26or\r\n4tmtwqjr1+xS9TGR0p9/JxD30Tcmoh7RgbbZ3aGzJ4nITpWk
3IVCYSzMU1mB\r\nvUVaYiTlHhTeUuOT7+7oCspuDZl5aFvlWFVigwY2JglrXoX06RKshpv+3KOn\r\nKOoaqwTtEndb2B37DC8jKNzrkXvzVovkAIc=\r\n=Iv/c\r\n-----END PGP SIGNATURE-----\r\n"
},
"_npmUser": "erisu <erisu.dev@outlook.jp>",
"directories": {},
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/cordova-plugin-device_2.1.0_1649642245870_0.2407506198810192"
},
"_hasShrinkwrap": false
}
{
"error": {
"code": "EACCES",
"summary": "Error: EACCES: permission denied, write",
"detail": "\nThe operation was rejected by your operating system.\nIt is likely you do not have the permissions to access this file as the current user\n\nIf you believe this might be a permissions issue, please double-check the\npermissions of the file and its containing directories, or try running\nthe command again as root/Administrator."
}
}
There is an extra "error" block at the end of the output. Very odd.
There is an extra "error" block at the end of the output. Very odd.
Indeed, very odd.
Does the raw command work for you? Try running: npm view cordova-plugin-device@2.1.0 --json
If it reproduces directly while running npm
, then that tells us that NPM is trying to do something that it doesn't have permission to do. If the error is inside the output of execa... then I would think it's NPM that is hitting that error...
Hello there Norman, running the command in a regular shell prompt works
fine. Is it something to do with the snap version of npm/node, I wonder?
I'll try to repro with a non-snap version tomorrow.
I do know that running apps under snap uses AppArmour which gives processes a fine grain control over what they can or can't do, or what directories/files they can access or can't access. I personally don't use snap cause often times these settings appears to be misconfigured for proper usage... at least that was my experience with them. But if you're running a snap version, and that's the version running in the same regular prompt, then I would have expected the issue to reproduce if it was an apparmour sandbox issue.
I use nvm
myself, which to me is the easiest way to manage using different node versions. So if you want to try different environments, I'd give that a go.
If all else fails... I think we'll need to run the command line under the node debugger, or add print statements to try to figure out where that error is coming from exactly.
Thanks breautek, this is working fine for me with both local and global installs of Cordova when I use node installed via nvm. I strongly suspect it's something weird with the snap version, and I might refer this issue to the snap maintainers.
The error message is kind of a red herring, I think, in that valid output is also returned and execa
is not throwing an error, which means that npm is returning a zero error code. I also can't think of anything that this operation should be doing that would need permissions, such as writing files, etc...
I think, in that valid output is also returned and execa is not throwing an error, which means that npm is returning a zero error code. I also can't think of anything that this operation should be doing that would need permissions, such as writing files, etc...
Yah it is strange. Even the app armor thing I mentioned before, it's still strange to see the correct stdout from NPM followed by an error in stdout.
It looks like it's been confirmed to be an issue with the snap version of Node. Because it isn't a bug actionable by Cordova I'll be closing this issue.