# فشل تثبيت npm بسبب سوء تكوين package.json

**URL:** https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193
**Category:** Development
**Created:** [3 نوفمبر 2018، 9:31ص UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193 "2018-11-03T09:31:37Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [3 نوفمبر 2018، 9:31ص UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/1 "2018-11-03T09:31:37Z")

</div>

Since the commit [Use Yarn to manage dependencies, cleanup unused bootstrap libs (#6436) · discourse/discourse@dc8a16b · GitHub](https://github.com/discourse/discourse/commit/dc8a16b43bf264b9001e3515aaba9dc9d5143228), running `npm install` fails.

Looking at the log file …

```plaintext
880 silly fetchPackageMetaData error for jquery.autoellipsis@git+https://github.com/pvdspek/jquery.autoellipsis.git premature close
881 silly fetchPackageMetaData error for favcount@git+https://github.com/chrishunt/favcount.git premature close
882 silly fetchPackageMetaData error for jquery-resize@git+https://github.com/cowboy/jquery-resize.git premature close

```

… installation fails for dependencies whose version is a git repository instead of a semantic version string. In particular, they fail if in the repostitory, there is no `package.json` file.

Discourse’s dependencies from `package.json`:

```json
"dependencies": {
  "ace-builds": "1.4.1",
  "bootbox": "3.2.0",
  "chart.js": "2.7.2",
  "favcount": "https://github.com/chrishunt/favcount",
  "handlebars": "4.0.5",
  "htmlparser": "https://github.com/tautologistics/node-htmlparser",
  "jquery": "3.3.1",
  "jquery-color": "1.0.0",
  "jquery-resize": "https://github.com/cowboy/jquery-resize/",
  "jquery.autoellipsis": "https://github.com/pvdspek/jquery.autoellipsis",
  "jquery.cookie": "1.4.1",
  "jquery-tags-input": "1.3.5",
  "magnific-popup": "1.1.0",
  "markdown-it": "8.4.1",
  "mousetrap": "https://github.com/discourse/mousetrap#firefox-alt-key",
  "pikaday": "1.7.0",
  "resumablejs": "1.1.0",
  "spectrum-colorpicker": "1.8.0"
}

```

Is `npm install` still supposed to work or is Yarn the only option here?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3 نوفمبر 2018، 9:55ص UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/2 "2018-11-03T09:55:36Z")

</div>

This is a development question, not an install question, yes?

---

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [3 نوفمبر 2018، 10:04ص UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/3 "2018-11-03T10:04:11Z")

</div>

Is it? I wasn’t quite sure. Are these dependencies only relevant for Discourse’s testing? Then the category was wrong indeed. Sorry about that.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [5 نوفمبر 2018، 1:05ص UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/4 "2018-11-05T01:05:41Z")

</div>

@pmusaraj any tips here? Also … why are you using npm, we only really test using yarn and only support yarn for dev.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [5 نوفمبر 2018، 1:58ص UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/5 "2018-11-05T01:58:50Z")

</div>

I think the error you’re getting is due to our `package.json` using yarn syntax for referencing Github versions of dependencies. So, use `yarn install` instead of npm. Also, `yarn install` is only required for running frontend (qunit) tests or when a developer is upgrading one of the Discourse dependencies listed in `package.json`.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [5 نوفمبر 2018، 2:07ص UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/6 "2018-11-05T02:07:08Z")

</div>

I wonder if there is some entry we can add to our `package.json` that would force `npm install` to explode with a “sorry, npm is not supported use yarn”

Ultra low priority though.

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [5 نوفمبر 2018، 8:11ص UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/8 "2018-11-05T08:11:22Z")

</div>

@pmusaraj that seems like a good track to follow:

> <https://stackoverflow.com/questions/41076172/force-yarn-install-instead-of-npm-install-for-node-module/41112752#41112752>

---

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [5 نوفمبر 2018، 10:17ص UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/9 "2018-11-05T10:17:19Z")

</div>

I did not know that only Yarn is supposed to be used here. I saw a package.json and run `npm install` a short while ago to run my plugin tests. Now, `npm install` doesn’t work.

~~It looks like Yarn and NPM use incompatible syntax for referencing remote git repositories via URL so there is no nice common ground.~~  
Yarn does seem to support this as per [git+ssh install protocol is not used correctly · Issue #2500 · yarnpkg/yarn · GitHub](https://github.com/yarnpkg/yarn/issues/2500)

However, the missing package.json in these repositories makes npm fail.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [5 نوفمبر 2018، 1:37م UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/10 "2018-11-05T13:37:02Z")

</div>

@kleinfreund there is absolutely no need to run `npm install`. And as Sam and Joffrey point out, we will shortly block running `npm install` on the repo. (Just use `yarn install`.)

---

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [5 نوفمبر 2018، 1:41م UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/11 "2018-11-05T13:41:50Z")

</div>

I get it. It’s just that I didn’t previously need Yarn, so I have to install it. That’s not a big deal though.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [5 نوفمبر 2018، 8:30م UTC](https://meta.discourse.org/t/npm-install-fails-due-to-package-json-misconfiguration/101193/12 "2018-11-05T20:30:01Z")

</div>

This commit adds a preinstall hook that stops `npm install` and outputs “NPM is not supported, please use Yarn instead.” to the user.  
[https://github.com/discourse/discourse/commit/0fdb4d0e46e8a9f0bfae9368546c99b8030b5d48](https://github.com/discourse/discourse/commit/0fdb4d0e46e8a9f0bfae9368546c99b8030b5d48)
