rniemeyer / knockout-jqAutocomplete

knockout-jqAutocomplete is a Knockout.js plugin designed to work with jQuery UI's autocomplete widget.
MIT License
49 stars 20 forks source link

npm packet.json is incorrect #37

Open gregveres opened 6 years ago

gregveres commented 6 years ago

Hi @rniemeyer

I am just moving my MVC app over to webpack and this package is one of the ones that I use. I was scratching my head as to why web pack was saying that it couldn't resolve the reference of require("knockout-jqautocomplete"). I had the npm package installed. It was clearly there in my npm_modules directory.

Then I started looking at the packages.json file for knockout and comparing it to knockout-jqautocomplete and I noticed that knockout had a main value in its json file and autocomplete did not. I added the main tag like this:

"main": "build/knockout-jqAutocomplete.js",

and all of a sudden it could find the package. So I think that main is required to tell the npm package user where the file is within the package. Would you be able to add that to the npm package?

gregveres commented 6 years ago

Getting another step closer, it looks like there are missing dependencies as well. The code depends on jquery and jquery-ui/autocomplete, but those aren't mentioned in the package.json file. I am not an expert on npm but I think that is where they are supposed to be mentioned.

I suspect that other people haven't run into this because they already have jquery and jquery-ui installed. I had jquery installed, but not jquery-ui.

Here is a snippet from jquery-validation's package.json indicating that it depends on jquery

  "main": "dist/jquery.validate.js",
  "dependencies": {
    "jquery": "^1.7 || ^2.0 || ^3.1"
  },
gregveres commented 6 years ago

You aren't alone in not having a main. The next package am dealing with is messenger from hubspot. They also don't have a main, so I did some reading to see if having a main is optional. This SO answer was useful https://stackoverflow.com/questions/22512992/node-js-package-json-main-parameter

There should be a main, but the answer also showed me how to work around it.

rniemeyer commented 6 years ago

@gregveres - hey! I am happy to make some changes, but it does already have a main in the package.json here: https://github.com/rniemeyer/knockout-jqAutocomplete/blob/master/package.json#L9. I can add the jquery/jquery UI dependencies though.

gregveres commented 6 years ago

That's weird. either my new glasses are failing me, or the version I was delivered didn't have it. I will check again since I have since deleted the npm package and decided to use it outside of npm.

OK, I just fetched it again and here is the package.json file that I get. It doesn't have main in it. I used this command to fetch it: npm install knockout-jqautocomplete

{
  "name": "knockout-jqautocomplete",
  "version": "0.4.4",
  "author": {
    "name": "Ryan Niemeyer"
  },
  "repository": {
    "type": "git",
    "url": "git://github.com/rniemeyer/knockout-jqAutocomplete.git"
  },
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-uglify": "0.x.x",
    "grunt-contrib-jshint": "0.x.x",
    "grunt-contrib-watch": "0.x.x",
    "grunt-contrib-concat": "0.x.x",
    "grunt-contrib-jasmine": "0.x.x",
    "grunt-template-jasmine-istanbul": "0.x.x",
    "grunt-bower-task": "~0.3.4"
  },
  "licenses": [
    {
      "type": "MIT",
      "url": "http://opensource.org/licenses/MIT"
    }
  ],
  "gitHead": "68d39ccd2d4686ade4ca6fd97a5cc6a8fe5ea3b9",
  "description": "knockout-jqAutocomplete ================ *knockout-jqAutocomplete* is a [Knockout.js](http://knockoutjs.com/) plugin designed to work with jQuery UI's [autocomplete widget](http://jqueryui.com/autocomplete/).",
  "bugs": {
    "url": "https://github.com/rniemeyer/knockout-jqAutocomplete/issues"
  },
  "homepage": "https://github.com/rniemeyer/knockout-jqAutocomplete#readme",
  "_id": "knockout-jqautocomplete@0.4.4",
  "scripts": {},
  "_shasum": "c40480a0ab58a040a0fb8fe52f6862ffe593e851",
  "_from": "knockout-jqautocomplete@>=0.4.4 <0.5.0",
  "_npmVersion": "2.11.3",
  "_nodeVersion": "0.12.2",
  "_npmUser": {
    "name": "rniemeyer",
    "email": "rniemeyer@gmail.com"
  },
  "maintainers": [
    {
      "name": "rniemeyer",
      "email": "rniemeyer@gmail.com"
    }
  ],
  "dist": {
    "shasum": "c40480a0ab58a040a0fb8fe52f6862ffe593e851",
    "tarball": "https://registry.npmjs.org/knockout-jqautocomplete/-/knockout-jqautocomplete-0.4.4.tgz"
  },
  "_npmOperationalInternal": {
    "host": "packages-9-west.internal.npmjs.com",
    "tmp": "tmp/knockout-jqautocomplete-0.4.4.tgz_1456497262995_0.6810770942829549"
  },
  "directories": {},
  "_resolved": "https://registry.npmjs.org/knockout-jqautocomplete/-/knockout-jqautocomplete-0.4.4.tgz",
  "readme": "ERROR: No README data found!"
}
rniemeyer commented 6 years ago

@gregveres - ok - try installing version 0.5.0. It looks like the main field was added to package.json after 0.4.4 was published. Sorry for the issues.

gregveres commented 6 years ago

Yup it is there now. I see the main and the dependencies . Nice.

Thank you. BTW, just this morning I found a solution using webpack config. I am using the solution for Hubspot's messenger and signalR. You can use the NormalModuleReplacementPlugin to rewrite the dependency. In this case, I could have left the import in my code like this:

import "knockout-jqAutocomplete

then in my webpack config, I could add this line in the plugins section:

new webpack.NormalModuleReplacementPlugin(/^knockout-jqAutocomplete$/, 'knockout-jqAutocomplete/build/knockout-jqAutocomplete.js'),

That would let webpack find the proper file without it being listed in main for the package.