nice-select2 icon indicating copy to clipboard operation
nice-select2 copied to clipboard

Can't import the library because of wrong "main" entry in package.json

Open CapsE opened this issue 2 years ago • 4 comments

Hi, you have an error in your package.json

{
  "name": "nice-select2",
  "version": "2.1.0",
  "description": "A lightweight Vanilla JavaScript plugin that replaces native select elements with customizable dropdowns.",
  "main": "src/js/nice-select.js",
  "directories": {
    "doc": "docs"
  }
  ...

You're pointing to src/js/nice-select.js but the file is acutally named nice-select2.js this leads to issue when I try to import the library using webpack.

CapsE avatar Oct 05 '23 11:10 CapsE

Fixed https://github.com/bluzky/nice-select2/commit/964cbee17fecc22c9ebc86ad3795abe8b04cf47d

kodie avatar Oct 12 '23 16:10 kodie

The problem persists when installing via npm

remderk avatar Jan 16 '24 12:01 remderk

This issue is still in the latest release 2.1.0 in both this Github repo releases, and npm @CapsE

jamesfawcett avatar Feb 23 '24 18:02 jamesfawcett

Anyone know if there a way to fix this ? I use vitejs and I got this error : "Failed to resolve entry for package "nice-select2". The package may have incorrect main/module/exports specified in its package.json."

I'm pretty sure it the same kind of issue,

I would really like to use nice-select2 for my project.

Thanks.

bdube30 avatar Mar 01 '24 01:03 bdube30

For all looking, while we wait for this to be updated in NPM, here's how I solved this on my end:

  1. Install patch-package: npm i patch-package. There are a few other steps here, found this great article.
  2. In node_modules/nice-select2/package.json, apply the changes in the commit above
  3. Run npx patch-package nice-select2 --exclude 'nothing'
  4. Run npm install
  5. Save your changes to git if so inclined.

dougblackjr avatar Mar 22 '24 14:03 dougblackjr

fixed in version 2.2.0

Tsjippy avatar Apr 16 '24 08:04 Tsjippy