Yarn: Does not always handle malformed package.json gracefully

Created on 25 Oct 2016  Â·  7Comments  Â·  Source: yarnpkg/yarn

First, thanks for your work on this project. I was overjoyed to hear about it! It seems like it solves many problems in the Node package management space.

Do you want to request a _feature_ or report a _bug_?

Report a bug.

What is the current behavior?

When I remove a comma in my package.json file that separates two sections, I get the following error message:

$ yarn
yarn install v0.16.1
error An unexpected error occured, please open a bug report with the information provided in "/mypath/myproject/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

The error log gives the following message:

...

Trace:
  SyntaxError: /mypath/myproject/package.json: Unexpected string
      at Object.parse (native)
      at /Users/apanozzo/.nvm/versions/node/v5.11.1/lib/node_modules/yarn/lib/util/fs.js:271:57
      at next (native)
      at step (/Users/apanozzo/.nvm/versions/node/v5.11.1/lib/node_modules/yarn/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
      at /Users/apanozzo/.nvm/versions/node/v5.11.1/lib/node_modules/yarn/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:20
      at run (/Users/apanozzo/.nvm/versions/node/v5.11.1/lib/node_modules/yarn/node_modules/core-js/library/modules/es6.promise.js:87:22)
      at /Users/apanozzo/.nvm/versions/node/v5.11.1/lib/node_modules/yarn/node_modules/core-js/library/modules/es6.promise.js:100:28
      at flush (/Users/apanozzo/.nvm/versions/node/v5.11.1/lib/node_modules/yarn/node_modules/core-js/library/modules/_microtask.js:18:9)
      at _combinedTickCallback (internal/process/next_tick.js:67:7)
      at process._tickCallback (internal/process/next_tick.js:98:9)

If the current behavior is a bug, please provide the steps to reproduce.

On my project I already have a yarn.lock file.

Take an existing working package.json file. Remove a comma from it. Attempt to run yarn (yarn install).

Example:

    "scripts": {
      "lint": "eslint webpack --ext .js --ext .jsx"
-   },
+   }
   "repository": {

What is the expected behavior?

I think that Yarn should attempt to parse the JSON file, and if it gets an error, to then give me hints on how to fix it. In my case it was easy since I recently changed that file, but it might have been harder to track down. It's not immediately clear from the error in the file what the issue is. I also saw what NPM says when I try to run npm install with the same package.json file:

npm WARN Failed to parse json
npm WARN Unexpected token 'r' at 44:4
npm WARN   "repository": {
npm WARN    ^
npm WARN File: /mypath/myproject/package.json

This at helps guide me to look around where the underlying problem is.

Please mention your node.js, yarn and operating system version.

$ nvm list
->      v5.11.1
$ yarn --version
0.16.1

Mac OS X El Capitan (10.11.6)

All 7 comments

👋 ill take a stab at it later today

This is duplicate of #1229 and was fixed in #1424.

Now when ran against master:

$ yarn
info No lockfile found.
error Error parsing JSON at "/Users/neil/Projects/external/yarn-example/package.json", "/Users/neil/Projects/external/yarn-example/package.json: Unexpected token } in JSON at position 144".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

@panozzaj yea, after git pull i could not replicate

Sorry for the red herring, and thanks for taking the time to look at this!

The pull request template said to use the latest version and I interpreted
that as the last official release. But maybe it could be updated to say to
use master instead while the project is newish or in flux if that is more
accurate generally. I would be happy to amend the PR template if it would
cut down on ambiguity. Let me know if you would find that helpful and I can
make a PR. Thanks again!

On Oct 25, 2016 5:14 PM, "Alec" [email protected] wrote:

@panozzaj https://github.com/panozzaj yea, after git pull i could not
replicate

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/yarnpkg/yarn/issues/1448#issuecomment-256177804, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AADHsPR06hfDaXZb8WKbJ5YCNXy2scBJks5q3nEagaJpZM4KgP2T
.

@panozzaj, thanks for your feedback. Don't quote me on this as I am new here, but I think the official releases are planned to be every 2 weeks. In the mean time, @Daniel15 is working on nightly builds to fill the gaps between official releases!

Super cool, thanks again Neil!

On Oct 25, 2016 6:03 PM, "Neil Kistner" [email protected] wrote:

@panozzaj https://github.com/panozzaj, thanks for your feedback. Don't
quote me on this as I am new here, but I think the official releases are
planned to be every 2 weeks. In the mean time, @Daniel15
https://github.com/Daniel15 is working on nightly builds to fill the
gaps between official releases!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/yarnpkg/yarn/issues/1448#issuecomment-256190285, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AADHsJvHKAnMNtleXg3BSxxLhqHRVx7Cks5q3nyYgaJpZM4KgP2T
.

Yes, we're going to have nightly releases very soon, along with easy ways to install them 😄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

baptistelebail picture baptistelebail  Â·  3Comments

chiedo picture chiedo  Â·  3Comments

NonPolynomial picture NonPolynomial  Â·  3Comments

sebmck picture sebmck  Â·  3Comments

FLGMwt picture FLGMwt  Â·  3Comments