bluzky/nice-select2

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

Closed this issue · 6 comments

CapsE commented

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.

kodie commented

Fixed 964cbee

The problem persists when installing via npm

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

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.

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.

fixed in version 2.2.0