7
votes

I recently installed Node.js, npm, ionic and cordova, as described at Ionic Getting Started

Now when I open my Visual Studio project the Bower/NPM window displays the following error:

System.AggregateException: One or more errors occurred. ---> Microsoft.NodejsTools.Npm.PackageJsonException: Error reading package.json at 'C:\Users\Colin\AppData\Roaming\npm\node_modules\cordova\node_modules\npm\node_modules\graceful-fs\package.json': Error reading package.json. The file may be parseable JSON but may contain objects with duplicate properties.

This appears to be due to a problem with the npm package. So how do I work-around this? Do I install an earlier version of Node, npm, cordova or graceful-fs? And how do I do that?

EDIT Following the comment from Vikas Vats I ran the following commands:

cordova -v I'm told my global version is 5.3.3

npm uninstall -g cordova

npm install -g [email protected]

I now get the same error reported in graceful-fs\package.json but this time it's in a different location:

C:\Users\Colin\AppData\Roaming\npm\node_modules\ionic\node_modules\ionic-app-lib\node_modules\ionic-cordova-lib\node_modules\npm\node_modules\graceful-fs\package.json

2
Your graceful-fs module has the issue.Open its package.json file in notepad and check if there is duplicate keys in this file. Reinstall only cordova package. - Vikas Sharma
@VikasVats Yes, there are duplicate keys, as listed in the npm issue I linked to. I tried re-installing an earlier version of Cordova, now I have a problem with the graceful-fs/package.json installed as a dependency of my ionic-app-lib. (see my edit) I'm thinking about installing an earlier version of npm, then re-installing each package that gives me an error, but I'm a beginner with npm, so would appreciate any advice - Colin
I think you have your answer on that github issue - plus-
Now this time the issue is with ionic package.Try to reinstall it.Make sure the versions are compatible with each other. - Vikas Sharma

2 Answers

0
votes

From https://github.com/npm/npm/issues/9965

Open C:\Users\Colin\AppData\Roaming\npm\node_modules\ionic\node_modules\ionic-app-lib\node_modules\ionic-cordova-lib\node_modules\npm\node_modules\graceful-fs\package.json in a text editor and remove the duplicate root keys:

  • engines
  • gitHead
  • bugs
  • homepage
  • _id
  • _shasum
  • _from
  • _npmVersion
  • _nodeVersion
  • _npmUser
  • dist
  • repository
  • version

The root keys should only be present once in package.json

0
votes

I uninstalled cordova - taking it back to the version Visual Studio has been tested with:

npm uninstall -g cordova

npm install -g [email protected]

This moved the error to ionic. So I then took Ionic back to version 1.6.5:

npm uninstall -g ionic

npm install -g [email protected]

This fixed the graceful-fs/package.json file. I've copied the contents here:

{
  "author": {
    "name": "Isaac Z. Schlueter",
    "email": "[email protected]",
    "url": "http://blog.izs.me"
  },
  "name": "graceful-fs",
  "description": "A drop-in replacement for fs, making various improvements.",
  "version": "2.0.0",
  "repository": {
    "type": "git",
    "url": "git://github.com/isaacs/node-graceful-fs.git"
  },
  "main": "graceful-fs.js",
  "engines": {
    "node": ">=0.4.0"
  },
  "directories": {
    "test": "test"
  },
  "scripts": {
    "test": "tap test/*.js"
  },
  "keywords": [
    "fs",
    "module",
    "reading",
    "retry",
    "retries",
    "queue",
    "error",
    "errors",
    "handling",
    "EMFILE",
    "EAGAIN",
    "EINVAL",
    "EPERM",
    "EACCESS"
  ],
  "license": "BSD",
  "readme": "# graceful-fs\n\ngraceful-fs functions as a drop-in replacement for the fs module,\nmaking various improvements.\n\nThe improvements are meant to normalize behavior across different\nplatforms and environments, and to make filesystem access more\nresilient to errors.\n\n## Improvements over fs module\n\ngraceful-fs:\n\n* keeps track of how many file descriptors are open, and by default\n  limits this to 1024. Any further requests to open a file are put in a\n  queue until new slots become available. If 1024 turns out to be too\n  much, it decreases the limit further.\n* fixes `lchmod` for Node versions prior to 0.6.2.\n* implements `fs.lutimes` if possible. Otherwise it becomes a noop.\n* ignores `EINVAL` and `EPERM` errors in `chown`, `fchown` or\n  `lchown` if the user isn't root.\n* makes `lchmod` and `lchown` become noops, if not available.\n* retries reading a file if `read` results in EAGAIN error.\n\nOn Windows, it retries renaming a file for up to one second if `EACCESS`\nor `EPERM` error occurs, likely because antivirus software has locked\nthe directory.\n\n## Configuration\n\nThe maximum number of open file descriptors that graceful-fs manages may\nbe adjusted by setting `fs.MAX_OPEN` to a different number. The default\nis 1024.\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/isaacs/node-graceful-fs/issues"
  },
  "_id": "[email protected]",
  "_from": "graceful-fs@2"
}

I also tried the next Ionic release - 1.7.0 and the most recent one - 1.7.7. The problem came back, so I will stick with 1.6.5 for now

Reference Ionic releases