Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with importing package through ES6 notation #57

Open
AleAtSoftplace opened this issue May 23, 2023 · 2 comments
Open

Issue with importing package through ES6 notation #57

AleAtSoftplace opened this issue May 23, 2023 · 2 comments

Comments

@AleAtSoftplace
Copy link

Hello,
I've installed the package through NPM and I'm trying to import it in my project, but when I try to

import * as ns from "nice-select2"
window.NiceSelect = ns;

I get a "Package is not installed" error.
The package is present in the node_modules directory.

My stack is Vite v4.3.8 and Tailwind 3.3.2
This is the full error log, I think something in the manifest or exports could be wrong.

9:57:06 AM [vite] Internal server error: Failed to resolve entry for package "nice-select2". The package may have incorrect main/module/exports specified in its package.json.
Plugin: vite:import-analysis
File: /var/www/html/resources/js/app.js
at packageEntryFailure (file:///var/www/html/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:23382:11)
at resolvePackageEntry (file:///var/www/html/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:23379:5)
at tryNodeResolve (file:///var/www/html/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:23113:20)
at Context.resolveId (file:///var/www/html/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:22874:28)
at async Object.resolveId (file:///var/www/html/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:42847:32)
at async TransformContext.resolve (file:///var/www/html/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:42575:23)
at async normalizeUrl (file:///var/www/html/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:40500:34)
at async file:///var/www/html/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:40651:47
at async Promise.all (index 7)
at async TransformContext.transform (file:///var/www/html/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:40577:13)

@maykbrito
Copy link

maykbrito commented Aug 27, 2023

Add this line to this module's package.json node_modules/nice-select2/package.json

"module": "dist/js/nice-select2.js",

@justin-oh
Copy link

justin-oh commented Aug 31, 2023

I'm also running into an issue with the module not being recognized through the syntax import NiceSelect from 'nice-select2';.

I'm using Symfony's Webpack Encore and receiving this error:

Module build failed: Module not found:
"./assets/backend/backend.js" contains a reference to the file "nice-select2".
This file can not be found, please check it for typos or update it if the file got moved.

My work-around was to reference the file directly, based on my project's directory structure:

import NiceSelect from '../../node_modules/nice-select2/src/js/nice-select2.js';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants