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

Double module import of external library #9251

Closed
7 tasks done
Kolobok12309 opened this issue Jul 20, 2022 · 3 comments
Closed
7 tasks done

Double module import of external library #9251

Kolobok12309 opened this issue Jul 20, 2022 · 3 comments

Comments

@Kolobok12309
Copy link

Describe the bug

We write some library with .vue components and utils (for this components and other). This utils can have some state, and methods for change it(keys is symbols). In real project with vite(Nuxt3 setup) we found duplication of imported modules(by console.log)

This problem from vite or vue-plugin, can't say for sure, sometimes module load 2 times, sometimes 3, and this critical because we use symbols

Problem is similar to #7323

In repro duplicates is /node_modules/.vite/deps/chunk-VQ4VIJMT.js?v=3a551489 and /node_modules/shared/shared.js
.vue file is initiator of shared.js, and simple .js is initiator of chunk-VQ4VIJMT.js?v=3a551489 file

Reproduction

https://github.com/Kolobok12309/vitejs-double-file-load

System Info

System:
    OS: macOS 12.4
    CPU: (10) x64 Apple M1 Max
    Memory: 1.02 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.19.3 - ~/.nvm/versions/node/v14.19.3/bin/node
    Yarn: 1.22.15 - /usr/local/bin/yarn
    npm: 6.14.17 - ~/.nvm/versions/node/v14.19.3/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Firefox: 95.0.2
    Safari: 15.5
  npmPackages:
    @vitejs/plugin-vue: ^2.3.3 => 2.3.3 
    vite: ^3.0.1 => 3.0.2

Used Package Manager

yarn

Logs

No response

Validations

@Kolobok12309 Kolobok12309 changed the title Double module import Double module import of external library Jul 20, 2022
@Kolobok12309
Copy link
Author

Connected repo with minimal library
https://github.com/kolobok12309/vite-library-bug-double-load

@bluwy
Copy link
Member

bluwy commented Jul 23, 2022

I think this is a duplicate of #3910. The workaround for now is to add that library, e.g. vite-library-bug-double-load, to optimizeDeps.exclude, and if there's any CJS deps used by that library, it needs to be re-added to optimizeDeps.include, e.g. vite-library-bug-double-load > cjs-dep.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2022
@Kolobok12309
Copy link
Author

@bluwy, you are right, is duplicate, i didn't see this issue. But optimizeDeps.exclude: ['shared'] don't work for this minimal repro

@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants