Skip to content
This repository was archived by the owner on Mar 21, 2023. It is now read-only.

fixed "SyntaxError: The requested module '/jquery/dist/jquery.js' does not provide an export named default" #61

Open
wants to merge 1 commit into
base: npm-publish-code-for-vue3
Choose a base branch
from

Conversation

vivazzi
Copy link

@vivazzi vivazzi commented May 24, 2022

jquery.js module must have export default function, if it is need to import like this import $ from 'jquery';, but jquery does not have export default function.
In this pull request I added other way to use jquery: import * as Jquery from 'jquery';, which load module to Jquery variable.

Another way can be to use separated file (says, named jquery_compat.js), like this:

import 'jquery.js';
export default window.jQuery.noConflict(true);

And in Select2.vue to use:

import $ from "./jquery_compat.js";

If it need I will fix my pull request with second way of bug solution.

Using import * as Jquery from 'jquery'; is a bit ugly way in my opinion, because we cannot use jQuery.noConflict. But I don't know another way to fix this bug. If anyone knows a better fix than both above, please comment.

@vivazzi
Copy link
Author

vivazzi commented May 26, 2022

Sorry, I accidentally forgot to create a new branch from npm-publish-code-for-vue3. If you want I can create a new pull request with a new branch

@vivazzi
Copy link
Author

vivazzi commented May 27, 2022

Unfortunately, my pull request gets error when I run vite build:

index.813ae237.js:1 ReferenceError: $ is not defined

In production code I see that jQuery was loaded to index.813ae237.js, but it seems component did not apply window.jQuery = window.$ = jQuery;.

I don't know why it do so...

My all scenarios of running Select2:

  1. If Select.vue has import $ from 'jquery'; on line 8 (as in repo owner):
  • 1.1. if I run vite dev, then I get error:
Uncaught SyntaxError: The requested module '/node_modules/.pnpm/[email protected]/node_modules/jquery/dist/jquery.js?v=d0d02272' does not provide an export named 'default'
  • 1.2. if I run vite build and vite preview, then I get error:
index.6b32860a.js:1 TypeError: Bc(...).find(...).select2 is not a function
    at Proxy.mounted (index.6b32860a.js:31:4388)
    at en (index.6b32860a.js:1:12559)
    at St (index.6b32860a.js:1:12638)
    at Array.r.__weh.r.__weh (index.6b32860a.js:1:22610)
    at Lo (index.6b32860a.js:1:14082)
    at et (index.6b32860a.js:1:41980)
    at mount (index.6b32860a.js:1:31893)
    at Object.r.mount (index.6b32860a.js:1:53415)
    at index.6b32860a.js:31:5272
  1. If Select.vue has import * as jQuery from 'jquery'; on line 8 (as in my pull request):
  • 2.1. if I run vite dev, my code works good.

  • 2.2. if I run vite build and vite preview, then I get error:

index.813ae237.js:1 ReferenceError: $ is not defined
    at Proxy.mounted (index.813ae237.js:31:4347)
    at en (index.813ae237.js:1:12559)
    at St (index.813ae237.js:1:12638)
    at Array.Mr.r.__weh.r.__weh (index.813ae237.js:1:22610)
    at Lo (index.813ae237.js:1:14082)
    at et (index.813ae237.js:1:41980)
    at mount (index.813ae237.js:1:31893)
    at Object.r.mount (index.813ae237.js:1:53415)
    at index.813ae237.js:31:5271

AI try different ways to fix this bug, but all my attemps are failed. Has anybody ideas to decide this problem?

I found some information about it in jquery repo: jquery/jquery#4592

@javad-heidarpour
Copy link

javad-heidarpour commented Sep 15, 2022

@javad-heidarpour
Copy link

But then it gives me an error again:
1111

@soolingiprop
Copy link

import * as jQuery from 'jquery';
import select2 from 'select2';
select2(jQuery);

its working on laravel + vue3

@vivazzi
Copy link
Author

vivazzi commented Oct 2, 2022

It seems this repository is abandoned (there are no new updates). I suggest to use other solutions of filterable select in vue without jquery (more details: #58 (comment)).

But this pull request demonstare more global problem with jquery integration with vite + vue, so I didn't close or delete this pull request. This information can be useful for someone.

When Jquery will have ESM support, this information in this pull request will be deprecated.

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

Successfully merging this pull request may close these issues.

3 participants