Npm install fails due to package.json misconfiguration

Since the commit https://github.com/discourse/discourse/commit/dc8a16b43bf264b9001e3515aaba9dc9d5143228, running npm install fails.

Looking at the log file …

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:

"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?

1 Like

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

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.

1 Like

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

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.

5 Likes

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.

4 Likes

@pmusaraj that seems like a good track to follow:

2 Likes

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 https://github.com/yarnpkg/yarn/issues/2500

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

@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.)

2 Likes

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.

1 Like

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

8 Likes